Var
  P:Int64;
  N,M,Q,I,K:LOnGint;
  A:Array [1..100000] of Int64;
Begin
  Assign(Input,'irrelevant.in');   Reset(Input);
  Assign(Output,'irrelevant.out'); Rewrite(Output);
  Read(N,M);
  If N=1 then
    Begin
      Write('0');
      Close(Output);
      Halt(0);
    End;
  P:=N-1;
  If P mod M=0 then
    Begin
      Q:=1;
      A[Q]:=N-1;
    End;
  If Odd(N) then K:=(N div 2)+1
            else K:=N div 2;
  For I:=3 to K do
    Begin
      P:=(P*(N-I+1)) div (I-1);
      If P mod M=0 then
        Begin
          Inc(Q);
          A[Q]:=P;
        End;
    End;
  If (Odd(N))and(P mod M=0) then
     Begin
       Writeln((2*Q)-1);
       For I:=1 to Q-1 do Write(A[i],' ',A[i],' ');
       Write(A[Q]);
     End
  Else
    Begin
      Writeln(2*Q);
      For I:=1 to Q do Write(A[i],' ',A[i],' ');
    End;
  Close(Output);
End.