program Project1;

{$APPTYPE CONSOLE}


uses
  SysUtils;

var  n, m, i,toro,k,t,leo: Longint;
     a: array[1..100000] of Integer;
     b:array[1..10000000] of longint;
     mmart,kili: Boolean;

{***************************************************}

function mamravl(x, y: Longint): Longint;
var lv, yy: Longint;
begin
  lv := 0;
  yy := y;

  while (yy <= x) do
  begin
    lv := lv+ (x div yy);
    yy := yy * y;
  end;

  Result := lv;
end;

{***************************************************}

begin

  AssignFile(Input, 'irrelevant.in');
  Reset(Input);
  AssignFile(Output, 'irrelevant.out');
  Rewrite(Output);

  Read(n, m);

  FillChar(a, sizeof(a), 0);

  mmart := True;
   leo:=m;
  for i := 2 to  round(sqrt(m))+1  do
    if m mod i = 0 then
      while (m mod i = 0) do
      begin
        inc(a[i]);
        m := m div i;
        mmart := False;
      end;
    m:=leo;
  toro:=0;
  t:=1;
  if mmart then
  begin
    for k:=0 to n-1 do
  if (mamravl(n-1,m)-mamravl(k,m)-mamravl(n-k-1,m))>=1 then
  begin
  b[t]:=k+1;
  t:=t+1;
  toro:=toro+1;
  end;
  end

  else
  begin
  for k:=0 to  n-1 do
        begin
  kili:=true;
  for i:=2 to m do
  if (mamravl(n-1,i)-mamravl(k,i)-mamravl(n-k-1,i))<a[i] then
             begin
  kili:=false;
  break;
             end;
  if kili then
                  begin
  toro:=toro+1;
  b[t]:=k+1;
  t:=t+1;
                  end;



        end;





      end;
  Writeln(toro);
 for i:=1 to toro do
  write(b[i],' ');
  CloseFile(Input);
  CloseFile(Output);
end.

