

{$APPTYPE CONSOLE}
{$Q-,R-}
var
  a,d,dd:array[1..102000] of integer;
  pr,prl:array[1..100000] of longint;
  n,m,npr,md:longint;

procedure allprimes;
var cyc1,cyc2,sc:integer;
fl1:boolean;
begin
  pr[2]:=1;
  prl[1]:=2;
  sc:=1;
  for cyc1:=3 to 100000 do
	begin
	  cyc2:=2;
	  fl1:=true;
	  while (cyc2<=sqrt(cyc1))and(fl1) do
		begin
		  fl1:=fl1 and (cyc1 mod cyc2<>0);
		  inc(cyc2);
		end;
	  if fl1 and (m mod cyc1=0) then
		begin
		  inc(sc);
		  pr[cyc1]:=sc;
		  prl[sc]:=cyc1;
		end;
	end;
  npr:=sc;
end;

function nod(X,Y:longint):longint;
begin
  if X mod Y=0 then nod:=Y else
	nod:=nod(Y,X mod Y);
end;

procedure mult(X,Y:longint);
var nod1,i:longint;
begin
  nod1:=nod(X,Y);
  x:=x div nod1;
  y:=y div nod1;
  i:=1;
  while (i<=npr) do
	begin
	  while (x mod prl[i]=0) do
		begin
		  inc(a[pr[prl[i]]]);
		  x:=x div prl[i];
		end;
	  while (y mod prl[i]=0) do
		begin
		  dec(a[pr[prl[i]]]);
		  y:=y div prl[i];
		end;
	  inc(i);
	end;

end;

function GetM:boolean;
var
  i,cyc1:longint;
  x:longint;
begin
  fillchar(d,sizeof(d),0);

  i:=2;
  x:=m;
  while (x>1)and(i<=n) do
	begin
	  while (x mod i=0) do
		begin
		  inc(d[pr[i]]);
		  x:=x div i;
		end;
	  inc(i);
	end;
  if (i<=n) then
	begin
	  getm:=true;
	  md:=0;
	  for cyc1:=1 to npr do
		if d[cyc1]<>0 then
		  begin
			inc(md);
			dd[md]:=prl[cyc1];
		  end;
	end else getm:=false;

end;


function isdiv:boolean;
var
  fl1:boolean;
  cyc1:integer;
begin
  fl1:=true;
  for cyc1:=1 to md do
	fl1:=fl1 and (a[pr[dd[cyc1]]]>=d[pr[dd[cyc1]]]);
  isdiv:=fl1;
end;

var
   cyc1,j,sc:longint;
   fl1:boolean;
   ans:array[1..100000] of longint;
begin
  Assign(Input, 'irrelevant.in');
  Reset(Input);
  Assign(Output, 'irrelevant.out');
  Rewrite(Output);
  readln(n,m);
  allprimes;
  if getm then
	begin
	  sc:=0;
	  fillchar(a,sizeof(a),0);
	  for cyc1:=1 to ((n-1) div 2) do
		begin
		  mult(n-cyc1,cyc1);
		  if isdiv then
			begin
			  if cyc1=n div 2 then fl1:=true;
			  inc(sc);
			  ans[sc]:=cyc1+1;
			end;
		end;
	  if (n mod 2=0) then
		begin
		  for cyc1:=1 to sc do
			ans[2*sc+1-cyc1]:=n+1-ans[cyc1];
		  sc:=2*sc;
		end
	  else
		begin
		  if fl1 then
		begin
		  for cyc1:=1 to sc-1 do
			ans[2*sc-cyc1]:=n+1-ans[cyc1];
		  sc:=2*sc-1;
		end
	  else
		begin
		  for cyc1:=1 to sc do
			ans[2*sc+1-cyc1]:=n+1-ans[cyc1];
		  sc:=2*sc;
		end;
		end;
	  writeln(sc);
	  for cyc1:=1 to sc do
		write(ans[cyc1],' ');
	end
   else writeln(0);
  Close(input);
  Close(Output);
end.
