#include <bits/stdc++.h>
long long P;
int K, ans[110];
int main() {
  int i, j;
  long long x, y;
  scanf("%I64d%d", &P, &K);
  for (i = 0; P >= K; i += 2) {
    x = P / K;
    y = (x + K - 1) / K;
    ans[i] = P % K;
    ans[i + 1] = K * y - x;
    P = y;
  }
  if (P <= 0) goto FAIL;
  printf("%d\n", i + 1);
  for (j = 0; j < i; j++) printf("%d ", ans[j]);
  printf("%I64d", P);
  return 0;
FAIL:
  printf("-1");
  return 0;
}
