program Project1;

{$APPTYPE CONSOLE}

{$O+,Q+,R+}

uses
  SysUtils;

var  n, m, i, toro, k, tmp: Longint;
     a: array[1..1000000] of Extended;
     b: array[1..1000000] of Longint;
     mmart, kili: Boolean;

{***************************************************}

function mamravl(x, y: Extended): Extended;
var yy, xx, lv: extended;
begin
  lv := 0;
  yy := y;
  xx := x;

  while (yy <= xx) do
  begin
    lv := lv + trunc(xx / yy);
    yy := yy * y;
  end;

  Result := Trunc(lv);
end;

{***************************************************}

begin

  AssignFile(Input, 'irrelevant.in');
  Reset(Input);
  AssignFile(Output, 'irrelevant.out');
  Rewrite(Output);

  Read(n, m);

  FillChar(a, sizeof(a), 0);

  mmart := True;
  tmp := m;

  for i := 2 to  Round(Sqrt(m)) + 1  do
    if (m mod i = 0) then
      while (m mod i = 0) do
      begin
        a[i] := a[i] + 1;
        m := m div i;
        mmart := False;
      end;


  m := tmp;
  toro := 0;

  if mmart then
  begin
    for k := 0 to n-1 do
      if (mamravl(n-1, m) -
          mamravl(k, m) -
          mamravl(n-k-1, m) >= 1) then
      begin
        toro := toro + 1;
        b[toro] := k + 1;
      end;
  end

  else
    for k := 0 to  n-1 do
    begin
      kili := True;

      for i := 2 to Round(Sqrt(m))+1 do
        if (mamravl(n-1, i) -
            mamravl(k, i) -
            mamravl(n-k-1, i) < a[i]) then
        begin
          kili := False;
          Break;
        end;


      if kili then
      begin
        toro := toro + 1;
        b[toro] := k + 1;
      end;

    end;

{**********************************************}

  Writeln(toro);

  for i := 1 to toro-1 do
    Write(b[i],' ');

  Writeln(b[toro]);

  CloseFile(Input);
  CloseFile(Output);
end.
