{$APPTYPE CONSOLE}

var
  n,m:integer;
  s,cn,k,max,k2,i,j,pn,bn:integer;
  p,a,b,c:array[1..100000] of integer;
  l:array[1..100000] of byte;
  f:boolean;

procedure test(k:integer);
begin
  for j:=1 to pn do
    if k mod p[j]=0 then
      exit;
  inc(pn);
  p[pn]:=k;
  l[k]:=1;
end;

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

  read(n,m);
  for i:=1 to 100000 do l[i]:=0;
  l[2]:=1; l[3]:=1;
  pn:=2; p[1]:=2; p[2]:=3;
  k2:=0; k:=0;
  while k2<100000 do
  begin
    inc(k);
    test(6*k-1);
    k2:=6*k+1;
    if k2<n then
      test(k2);
  end;

  j:=1; bn:=0;
  for i:=1 to 100000 do a[i]:=0;
  while (m<>1) and (j<=pn) do
  begin
    if m mod p[j]=0 then begin inc(bn); b[bn]:=p[j]; end;
    while m mod p[j]=0 do
    begin
      m:=m div p[j];
      dec(a[p[j]]);
    end;
    inc(j);
  end;

  if m<>1 then
    write(0)
  else
  begin
    max:=(n-1) div 2;
    for k:=1 to max do
    begin
      s:=n-k;

      for j:=1 to bn do
      begin
        if l[s]=1 then
        begin
          inc(a[s]);
          s:=1;
          break;
        end;
//        if s = 1 then break;
        while s mod b[j] = 0 do
        begin
          s := s div b[j];
          inc(a[b[j]]);
        end;
      end;
{      j:=1;
      while (s>1) and (j<=pn) do
      begin
        if l[s]=1 then
        begin
          inc(a[s]);
          s:=1;
          break;
        end;
        while s mod p[j]=0 do
        begin
          s:=s div p[j];
          inc(a[p[j]]);
        end;
        inc(j);
      end;}

      s:=k;
      for j:=1 to bn do
      begin
        if l[s]=1 then
        begin
          dec(a[s]);
          s:=1;
          break;
        end;
//        if s = 1 then break;
        while s mod b[j] = 0 do
        begin
          s := s div b[j];
          dec(a[b[j]]);
        end;
      end;
{      j:=1;
      while (s>1) and (j<=pn) do
      begin
        if l[s]=1 then
        begin
          dec(a[s]);
          s:=1;
          break;
        end;
        while s mod p[j]=0 do
        begin
          s:=s div p[j];
          dec(a[p[j]]);
        end;
        inc(j);
      end;}

      f:=true;
      for j:=1 to bn do
        if a[b[j]]<0 then
        begin
          f:=false;
          break;
        end;

      if f then
      begin
        inc(cn);
        c[cn]:=k+1;
      end;
    end;

    j:=cn;
    for i:=cn downto 1 do
      if c[i]<>n-c[i]+1 then
      begin
        inc(j);
        c[j]:=n-c[i]+1;
      end;
    cn:=j;
    writeln(cn);
    for i:=1 to cn-1 do
      write(c[i],' ');
    if cn>0 then
      write(c[cn]);
  end;
end.
