{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
type
    tans = array [0..10000] of boolean;
var
   n,m : integer;
   ans : tans;

Procedure Init;
Begin
   fillchar(ans,sizeof(ans),false);
   read(n,m);
   n := n -1 ;
End;

function GCD(a,b : int64) : int64;
begin
   while (a > 1) or (b > 1) do begin
      if a > b then begin
         a := a - (a div b) * b;
         if a = 0 then begin
            Result := b;
            exit;
         end;
      end else begin
         b := b - (b div a) * a;
         if b = 0 then begin
            Result := a;
            exit;
         end;
      end;
   end;
   Result := 	1;
end;

function GetMD(a,b : int64) : int64;
begin
   Result := 1;
   while GCD(a,b) > 1 do begin
      Result := Result * GCD(a,b);
      a := a div GCD(a,b);
   end;
end;

Procedure Solve;
var
   k : integer;
   c : int64;
   a,b : int64;
   step : integer;
Begin
   c := 1;
   step := 0;
   for k := 1 to n do begin
      a := GetMD(n-k+1,m);
      b := GetMD(k,m);
      c := c*a;
      while c mod b <> 0 do begin
         dec(step);
         c := c*m;
      end;
      c := c div b;
      while c mod m = 0 do begin
         c := c div m;
         inc(step);
      end;
      if step > 0 then
         ans[k+1] := true;
   end;       
End;

Procedure Save;
var
   cnt,i : integer;
Begin
   cnt := 0;
   for i := 1 to n do
      if ans[i] then
         inc(cnt);
   writeln(cnt);
   for i := 1 to n do
      if ans[i] then  begin
         write(i,' ');
      end;
End;

begin
assign(input,'irrelevant.in'); reset(input);
assign(output,'irrelevant.out'); rewrite(output);
  Init;
  Solve;
  Save;
close(input);
close(output);
end.
 