{$R-,Q-,O+}
{$MINSTACKSIZE $00404000}
{$APPTYPE CONSOLE}
type
  int = longint;

var
  n, m, pnum, u: int;
  p: array [1..40000] of int;
  mark: array [1..40000] of boolean;
  pn, ps: array [1..20] of int;
  ans: array [1..110000] of int;

procedure init;
var
  i, j: int;
  
begin
  pnum:=0;
  for i:=2 to 40000 do
  begin
    if (mark[i]) then
      continue;

    inc(pnum);
    p[pnum]:=i;

    j:=i;
    while (j <= 40000) do
    begin
      mark[j]:=true;
      inc(j, i);
    end;
  end;

  u:=0;
  for i:=1 to pnum do
    if (m mod p[i] = 0) then
    begin
      inc(u);
      pn[u]:=p[i];
      ps[u]:=0;
      while (m mod p[i] = 0) do
      begin
        inc(ps[u]);
        m:=m div p[i];
      end;
    end;

  if (m > 1) then
  begin
    inc(u);
    pn[u]:=m;
    ps[u]:=1;
    m:=1;
  end;

  assert(m = 1);
end;

procedure solve;
var
  i, w, k, t, q, aa: int;

label
  next;

begin
  w:=0;
  dec(n);
  for k:=0 to n do
  begin
    for i:=1 to u do
    begin
      t:=0;
      q:=n;
      while (q > 0) do
      begin
        aa:=q div pn[i];
        t:=t + aa;
        q:=aa;
      end;
      
      q:=k;
      while (q > 0) do
      begin
        aa:=q div pn[i];
        t:=t - aa;
        q:=aa;
      end;
      
      q:=n - k;
      while (q > 0) do
      begin
        aa:=q div pn[i];
        t:=t - aa;
        q:=aa;
      end;

      if (t < ps[i]) then
        goto next;
    end;

    inc(w);
    ans[w]:=k + 1;
next:    
  end;

  writeln(w);
  for i:=1 to w do
    writeln(ans[i]);
end;
  
begin
  assign(input, 'irrelevant.in');
  assign(output, 'irrelevant.out');
  reset(input);
  rewrite(output);

  read(n, m);
  init;
  solve;
end.
