#include <bits/stdc++.h>
using namespace std;
long long p, k, i, j, l, kk;
vector<long long> v;
int main() {
  cin >> p >> k;
  if (p < k) i = 0;
  kk = 1;
  while (kk < p) {
    if (p / k < kk) break;
    kk *= k;
    i++;
  }
  l = 1;
  if (i % 2 == 1) l = -1;
  v.resize(i + 1);
  for (j = i; j > 0; j--) {
    v[j] = (p / kk) * l;
    p = p % kk;
    kk = kk / k;
    l = -l;
  }
  v[j] = (p / kk) * l;
  for (i = 0; i < v.size(); i++) {
    if (i % 2 == 1) {
      while (v[i] <= k) {
        v[i] = v[i] + k;
        if (i + 1 == v.size())
          v.push_back(1);
        else
          v[i + 1]++;
      }
      if (v[i] < 0) {
        v[i] = k + v[i];
        if (i + 1 == v.size())
          v.push_back(1);
        else
          v[i + 1]++;
      }
    }
    while (v[i] >= k) {
      v[i] = v[i] - k;
      if (i + 1 == v.size())
        v.push_back(-1);
      else
        v[i + 1]--;
    }
  }
  cout << v.size() << endl;
  for (i = 0; i + 1 < v.size(); i++) cout << v[i] << " ";
  cout << v[i] << "\n";
  return 0;
}
