program P_I;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  NN = 85;
var
  ans: array [1..100001] of boolean;
  d, c: array [1..NN] of byte;
  l, n, m, i, j, id, an: longint;
  K: int64;
  co: integer;


procedure gamr(M : longint);
begin
  co := 0;
  fillchar(c, sizeof(c), 0);
  for j := NN downto 2 do
  begin
    c[j] := (d[j] * M +  co) mod 10;
    co := (d[j] * M +  co) div 10;
  end;
  d := c;
end;

procedure gakop(M: longint);
begin
  id := 0;
  K := 0;
  fillchar(c, sizeof(c), 0);

  for j := 1 to NN do
  begin
    K := 10 * K + d[j];

    if K >= M then
    begin
      inc(Id);
      c[Id] := K div M;
      K := K mod M;
    end else
    if id > 0 then
      inc(id);


  end;

  for j := 1 to NN - ID + 1 do
    d[j] := 0;
  for j := 1 to id do
  begin
    d[NN - j + 1] := c[id - j + 1];
  end;
end;

function check(M: longint): boolean;
begin
  K := 0;
  for j := 1 to NN do
  begin
    K := 10 * K + d[j];
    if K >= M then
    begin
      inc(Id);
      K := K mod M;
    end;
  end;
  result := K =0;
end;


begin
  assign(input, 'irrelevant.in'); reset(input);
  read(n, m);
  close(input);
  l := n - 1;
  if m > 1 then
  begin
    d[NN] := 1;
    for i := 1 to l div 2 do
    begin
      gamr(l - i + 1);
      gakop(i);
      if check(m) then
      begin
        an := an + 2;
        ans[i + 1] := true;
        ans[l - i + 1] := true;
        if l - i = i  then
          an := an - 1;
      end;
    end;
  end else
  begin
    an := n;
    for i:= 1 to n do
      ans[i] := true;

  end;

  assign(output, 'irrelevant.out'); rewrite(output);
  writeln(an);
  for i := 1 to n do
  if ans[i] then
  begin
    writeln(i);
  end;
  close(output);
end.
