#include <bits/stdc++.h>
using namespace std;
long long p, k, i, n;
long long b[1000], ans[1000];
int main() {
  cin >> p >> k;
  if (p < k) {
    cout << 1 << endl;
    cout << p << endl;
    return 0;
  }
  b[0] = (-p) / k;
  i = 0;
  while (b[i] != 0) {
    if (b[i] > 0)
      b[i + 1] = (-b[i]) / k;
    else {
      if ((-b[i]) % k == 0) {
        b[i + 1] = (-b[i]) / k;
      } else
        b[i + 1] = (-b[i]) / k + 1;
    }
    i++;
  }
  n = i - 1;
  ans[0] = k * b[0] + p;
  ans[n + 1] = b[n];
  for (i = 1; i <= n; i++) ans[i] = k * b[i] + b[i - 1];
  cout << n + 2 << endl;
  for (i = 0; i <= n + 1; i++) {
    cout << ans[i];
    if (i != n + 1) cout << ' ';
  }
  cout << endl;
}
