{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE GUI}
program pr_i;

{$APPTYPE CONSOLE}


var
  c,d:array[-1..100001]of longint;
  x,y,n,m,ans,i,j,k:longint;
begin
  assign(input,'irrelevant.in');reset(input);
  assign(output,'irrelevant.out');rewrite(output);

  read(n,m);

  fillchar(c,sizeof(c),0);
  fillchar(d,sizeof(d),0);
  n:=n-1;
  c[0]:=0;
  d[0]:=0;
  for i:=1 to n do begin
    x:=n-i+1;
    y:=i;
    d[i]:=d[i-1];
    c[i]:=c[i-1];
    while (x mod m=0) do begin
      x:=x div m;
      inc(d[i]);
    end;
    while (y mod m=0) do begin
      y:=y div m;
      inc(c[i]);
    end;
    if (c[i]<d[i]) then inc(ans);
  end;
  writeln(ans);
  for i:=0 to n do begin
    if (c[i]<d[i]) then write(i+1,' ');
  end;
  writeln;

  close(input);
  close(output);
end.
