program prI;

{$APPTYPE CONSOLE}

var N, M, C, i, j, T, Count: integer;
    Cin: array [1..100] of integer;
    Marr: array [1..100, 1..2] of integer;
    IsAns: boolean;
    Res: array [1..100000] of integer;

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

  read(N, M);

  fillchar(Cin, sizeof(Cin), 0);
  fillchar(Marr, sizeof(Marr), 0);

  C:=0;
  for i:=2 to trunc(sqrt(M)) do begin
    if M mod i=0 then begin
      inc(C);
      Marr[C, 1]:=i;
    end;
    while M mod i=0 do begin
      inc(Marr[C, 2]);
      M:=M div i;
    end;
  end;

  if M>1 then begin
    inc(C);
    inc(Marr[C,2]);
    Marr[C,1]:=M;
  end;

  Count:=0;
  for i:=2 to (N+1) div 2 do begin
    IsAns:=true;
    for j:=1 to C do begin
      if (N-i+1) mod Marr[j, 1]=0 then begin
        T:=N-i+1;
        while T mod Marr[j, 1]=0 do begin
          inc(Cin[j]);
          T:=T div Marr[j, 1];
        end;
      end;
      if (i-1) mod Marr[j,1]=0 then begin
        T:=i-1;
        while T mod Marr[j,1]=0 do begin
          dec(Cin[j]);
          T:=T div Marr[j, 1];
        end;
      end;
    end;
    for j:=1 to C do begin
      if Cin[j]<Marr[j,2] then IsAns:=false;
    end;
    if IsAns then begin
      inc(Count);
      Res[Count]:=i;
    end;
  end;

  if (N mod 2=0) or (N mod 2=1) and (Res[Count]<>(N+1) div 2) then begin
    writeln(Count*2);
    for i:=1 to Count do write(Res[i], ' ');
    for i:=Count downto 1 do write(N-Res[i]+1, ' ');
  end else begin
    writeln(Count*2-1);
    for i:=1 to Count-1 do write(Res[i], ' ');
    write(Res[Count], ' ');
    for i:=Count-1 downto 1 do write(N-Res[i]+1, ' ');
  end;
end.
