program taskI;
{$APPTYPE CONSOLE}
const
   MAX = 100000;
var
   fi,fo:TextFile;
   n,m,t: Int64;
   a: array [1..MAX] of byte;
   i1,Cnt: longint;


begin
   AssignFile(fi,'irrelevant.in');
   AssignFile(fo,'irrelevant.out');
   Rewrite(fo);
   Reset(fi);

   Read(fi,n,m);

   t:=1; Cnt:=0;
   for i1:=2 to (n div 2) + (n mod 2) do
      begin
         t:=((t*(n-i1+1)) div (i1-1));// mod m;
         if t mod m =0 then
            begin
               if (n mod 2 =1) AND (i1 = (n div 2) + (n mod 2)) then inc(Cnt,1)
                                                                else inc(Cnt,2);
               a[i1]:=1;
               a[n-i1+1]:=1;
            end;
         //Writeln(t);
         {
         if t>10000000000000000 then
            begin
               Writeln('!');
            end;
         }
      end;
   //output
   Writeln(fo,Cnt);
   for i1:=1 to n do if a[i1]=1 then Write(fo,i1,' ');

   Close(fo);
   Close(fi);
end.
