#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p, k;
  cin >> p >> k;
  vector<long long> ans;
  do {
    long long b = 0;
    if (p >= 0) {
      b = p / k;
      b *= -1;
    } else {
      b = (-p + k - 1) / k;
    }
    if (p < 0 && k + p >= 0) {
      ans.push_back(k + p);
      ans.push_back(1);
      break;
    }
    if (p == 0) {
      break;
    }
    ans.push_back(k * b + p);
    p = b;
  } while (1);
  cout << ans.size() << endl;
  for (auto i : ans) cout << i << " ";
  cout << endl;
  return 0;
}
