#include <bits/stdc++.h>
using namespace std;
const int ms = 2e3 + 200;
long long f[ms];
long long ce(long long x, int d) {
  if (x < 0) {
    return -((-x) / d);
  } else {
    return (x + d - 1) / d;
  }
}
int main() {
  long long p;
  int k;
  cin >> p >> k;
  vector<long long> q;
  long long at = p;
  while (at > 1 && at >= k) {
    long long ls = ce(-at, k);
    q.push_back(ls);
    ls = ce(-ls, k);
    q.push_back(ls);
    at = ls;
  }
  int ok = 1;
  int d = 0;
  f[0] = p;
  for (int i = 0; i < q.size(); i++) {
    f[i] += q[i] * k;
    f[i + 1] += q[i];
    if (f[i] > 0) d = i;
    if (f[i] < 0) ok = 0;
    if (f[i] >= k) ok = 0;
  }
  if (f[q.size() + 1] > 0)
    d = q.size() + 1;
  else if (f[q.size() + 1] < 0)
    ok = 0;
  if (f[d] >= k) ok = 0;
  if (!ok) {
    puts("-1");
    return 0;
  }
  cout << q.size() + 1 << endl;
  for (int i = 0; i < q.size() + 1; i++) cout << f[i] << " \n"[i == q.size()];
}
