#include <bits/stdc++.h>
using namespace std;
vector<long long> out;
map<long long, int> ma;
int main() {
  long long p, k;
  cin >> p;
  cin >> k;
  ma[p] = 1;
  if (p < k) {
    cout << 1 << endl;
    cout << p << endl;
    return 0;
  }
  while (1) {
    long long a;
    if (p >= 0)
      a = -p / k;
    else
      a = (-p + k - 1) / k;
    out.push_back(p + a * k);
    p = a;
    if (p == 0) {
      cout << -1 << endl;
      return 0;
    }
    ma[p]++;
    if (p < (long long)k && p > 0LL) break;
  }
  out.push_back(p);
  int n = out.size();
  cout << n << endl;
  for (int i = 0; i < n; i++) {
    if (i < n - 1)
      cout << out[i] << ' ';
    else
      cout << out[i] << endl;
  }
}
