program Iggg;

{$APPTYPE CONSOLE}

uses
  SysUtils;

Var N,M                 : longint;
    i,NA                : longint;
    j                   : Int64;
    A                   : array [1..1000000] of longint;

Function StepMFact(X : longint) : Int64;
Var Ans, CurStep : Int64;
Begin
  Ans:=0; CurStep:=M;
  While CurStep<=X do Begin
    Ans:=Ans+(X div CurStep);
    CurStep:=CurStep*M;
  End;

  StepMFact:=Ans;
End;

begin
  { TODO -oUser -cConsole Main : Insert code here }
  AssignFile(input, 'irrelevant.in'); Reset(Input);
  AssignFile(output, 'irrelevant.out'); Rewrite(Output);

  Read(N,M);

  i:=StepMFact(33);

  If N<3 then Begin
    Writeln(0);
    close(input); close(output);
    Halt(0);
  End;

  NA:=0;
  For i:=0 to N-1 do Begin
    j:=StepMFact(N-1)-StepMFact(i)-StepMFact(N-1-i);
    If j>0 then Begin
      Inc(NA); A[Na]:=i+1;
    End;
  End;

  Writeln(NA);
  For i:=1 to NA do Write(A[i],' ');
  close(input); close(output);
end.
