{$o-}
program p_i;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  fin,fout:text;
  p,s:extended;
  n,m,k:longint;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  AssignFile(fin,'irrelevant.in');
  AssignFile(fout,'irrelevant.out');
  Reset(fin);
  Rewrite(fout);
  Readln(fin,n,m);
  n:=n-1;
  p:=1;
  s:=0;
  For k:=2 to n do
    begin
      p:=frac((p*(n-k+2)/(k-1))/m)*m;
      if frac(p/m)=0 then s:=s+1;
    end;
  Writeln(fout,s:0:0);
  p:=1;
  if m=1 then Write(fout,1,' ');
  For k:=2 to n do
    begin
      p:=frac((p*(n-k+2)/(k-1))/m)*m;
      if frac(p/m)=0 then Write(fout,k,' ');
    end;
  CloseFile(fin);
  CloseFile(fout);
end.
