#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, oo = inf;
char __wzp[1 << 15 | 1], *__S = __wzp + 32768;
inline long long read() {
  register long long x = 0, f = 1;
  register char c =
      (__S >= __wzp + 32768
       ? (__wzp[fread(__wzp, sizeof(char), 1 << 15, stdin)] = EOF),
       *((__S = __wzp)++) : *(__S++));
  for (; !isdigit(c);
       c = (__S >= __wzp + 32768
            ? (__wzp[fread(__wzp, sizeof(char), 1 << 15, stdin)] = EOF),
            *((__S = __wzp)++) : *(__S++)))
    if (c == '-') f = -1;
  for (; isdigit(c);
       c = (__S >= __wzp + 32768
            ? (__wzp[fread(__wzp, sizeof(char), 1 << 15, stdin)] = EOF),
            *((__S = __wzp)++) : *(__S++)))
    x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
long long a[1000009], b[1000009], n, p, k;
int main() {
  p = read(), k = read();
  n = 0;
  a[0] = p % k;
  b[0] = -p / k;
  while (b[n] != 0) {
    ++n;
    int w = b[n - 1];
    a[n] = (b[n - 1] % k + k) % k;
    b[n] = (a[n] - b[n - 1]) / k;
  }
  printf("%I64d\n", n + 1);
  for (register int i = (0); i <= (n); ++i) printf("%I64d ", a[i]);
  return 0;
}
