program test;

{$APPTYPE CONSOLE}
{$O-}
var
  ndiv,i:longint;
function simple(i:longint):boolean;
var
 	j:longint;
begin
	for j:=2 to round(sqrt(i)) do
  	if i mod j=0 then
    begin
    	simple:=false;
      exit;
    end;
  simple:=true;
end;
var
	dels:array[1..32000] of longint;
  pdels:array[1..32000] of longint;
procedure fill(a:longint);
var
	 i:longint;
begin
	for i:=1 to ndiv do
  begin
  	if a mod pdels[i]=0 then
    begin
    	while a mod pdels[i]=0 do
      begin
      	dec(dels[i]);
        a:=a div pdels[i];
      end
    end;
  end;
end;
procedure unfill(a:longint);
var
	 i:longint;
begin
	for i:=1 to ndiv do
  begin
  	if a mod pdels[i]=0 then
    begin
    	while a mod pdels[i]=0 do
      begin
      	inc(dels[i]);
        a:=a div pdels[i];
      end
    end;
  end;
end;
function check:boolean;
var
	i:longint;
begin
	for i:=1 to ndiv do
  begin
  	if dels[i]>0 then
    begin
    	check:=false;
      exit;
    end;
  end;
  check:=true;
end;
var
  fir,j,n,m:longint;
  res:array[1..1000001] of longint;
  cntres:longint;
begin
  assign(input,'irrelevant.in');
  assign(output,'irrelevant.out');
  readln(n,m);
  j:=0;
  for i:=2 to round(sqrt(m)) do
  begin
  	if (simple(i)) and (m mod i=0)then
    begin
      inc(j);
      dels[j]:=0;
      while m mod i=0 do
      begin
      	m:=m div i;
        inc(dels[j]);
      end;
      pdels[j]:=i;
    end;
  end;
  inc(j);
  dels[j]:=1;
  pdels[j]:=m;
  ndiv:=j;
  cntres:=0;
  for i:=1 to n div 2 do
  begin
    fill(n-i);
    unfill(i);
    if check then
    begin
        inc(cntres);
        res[cntres]:=i+1;

    end;
  end;
  writeln(cntres);
  for i:=1 to cntres do
  	write(res[i],' ');
  for i:=1 to cntres do
  begin
  	if res[i]<>n-res[i]+1 then
    	write(n-res[i]+1,' ');
  end;
end.
