program taski2;
{$APPTYPE CONSOLE}
{ $I+,Q+,R+,O-}
{$I-,Q-,R-,O+}
uses
  SysUtils,Math;
type
  short=smallint;
  long=longint;
  real=extended;
  bool=boolean;

  function getdeg(n,k: long): long;
  begin
    result:=0;
    while n>=k do begin
      n:=n div k;
      inc(result,n);
    end;
  end;

  function isprime(k: long): bool;
  var i,t: long;
  begin
    if k<2 then result:=false
    else if k<4 then result:=true
    else if not odd(k) then result:=false
    else begin
      t:=trunc(sqrt(k));
      i:=3;
      while i<=t do begin
        if k mod i=0 then begin
          result:=false;
          exit;
        end;
        inc(i,2);
      end;
      result:=true;
    end;
  end;

var
  n,m,k,i,c: long;
  p,d: array[1..100] of long;
  a: array[1..100000] of long;

  function mod0(n,m: long): bool;
  var i: long;
  begin
    result:=false;
    for i:=1 to k do
      if getdeg(n,p[i])-getdeg(m,p[i])-getdeg(n-m,p[i])<d[i] then
        exit;
    result:=true;
  end;

begin
  assign(input,'irrelevant.in'); reset(input);
  assign(output,'irrelevant.out'); rewrite(output);

  readln(n,m);
  k:=0;
  for i:=1 to round(sqrt(m)) do
    if isprime(i) then
      if m mod i=0 then begin
        inc(k);
        p[k]:=i;
        d[k]:=0;
        while m mod i=0 do begin
          inc(d[k]);
          m:=m div i;
        end;
      end;
  if m>1 then begin
    assert(isprime(m));
    inc(k);
    p[k]:=m;
    d[k]:=1;
  end;

  c:=0;
  for i:=1 to n do
    if mod0(n-1,i-1) then begin
      inc(c);
      a[c]:=i;
    end;

  writeln(c);
  for i:=1 to c do writeln(a[i]);

  close(input);
  close(output);
end.

