#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
long long a[1000005], c[1000005], n, k;
map<long long, bool> v;
int main() {
  c[0] = read();
  k = read();
  for (int i = 1; !(c[i - 1] >= 0 && c[i - 1] < k); i++) {
    if (v[a[i - 1] + inf])
      return 0 * printf("-1\n");
    else
      v[a[i - 1] + inf]++;
    if (c[i - 1] > 0) {
      a[i] = -c[i - 1] / k;
      c[i - 1] = c[i - 1] % k;
      c[i] = a[i];
    } else {
      a[i] = -c[i - 1] / k;
      c[i - 1] = c[i - 1] + a[i] * k;
      if (c[i - 1] < 0) c[i - 1] += k, a[i]++;
      c[i] = a[i];
    }
    n++;
  }
  printf("%I64d\n", n + 1);
  for (int i = 0; i <= n; i++) printf("%I64d ", c[i]);
  return 0;
}
