#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
long long a[maxn];
long long p[maxn];
long long k;
long long divup(long long lhs, long long rhs) {
  if (lhs >= 0) {
    return (lhs + rhs - 1) / rhs;
  } else {
    return (lhs) / rhs;
  }
}
int main() {
  while (cin >> p[0] >> k) {
    int d = 0;
    while (p[d]) {
      p[d + 1] = divup(-p[d], k);
      a[d] = p[d] + k * p[d + 1];
      d++;
    }
    printf("%d\n", d);
    for (int i = 0; i < d; i++) {
      printf("%lld%c", a[i], i == (d - 1) ? '\n' : ' ');
    }
  }
}
