#include <bits/stdc++.h>
using namespace std;
void Read(long long &x, char c = getchar(), bool f = 0) {
  for (x = 0; !isdigit(c); c = getchar())
    if (c == '-') f = 1;
  for (; isdigit(c); c = getchar()) x = 10 * x + c - '0';
  if (f) x = -x;
}
const long long maxn = 1e6 + 5;
long long n, m, p, k, a[maxn], b[maxn];
long long L[maxn], R[maxn];
int main() {
  long long i, d;
  Read(p), Read(k);
  L[0] = (long long)ceil((long double)-p / k);
  R[0] = (long long)floor((long double)(k - p - 1) / k);
  for (i = 1; i <= 1e6; i++) {
    L[i] = (long long)ceil(-(long double)R[i - 1] / k);
    R[i] = (long long)floor((long double)(k - L[i - 1] - 1) / k);
    if (L[i] > R[i]) {
      puts("-1");
      return 0;
    }
  }
  d = 1e6;
  b[0] = L[0];
  a[0] = b[0] * k + p;
  for (i = 1; i <= d; i++) {
    b[i] = L[i];
    a[i] = b[i] * k + b[i - 1];
  }
  for (i = d; i >= 0; i--)
    if (a[i]) {
      d = i;
      break;
    }
  cout << d + 1 << endl;
  for (i = 0; i <= d; i++) cout << a[i] << " ";
  return 0;
}
