#include <bits/stdc++.h>
using namespace std;
long long modu(long long a, long long b) {
  if (a < 0) a += ((abs(a) + b - 1) / b) * b;
  return a % b;
}
int main() {
  int k;
  long long p, x;
  cin >> p >> k;
  vector<long long> ans;
  while (p) {
    x = modu(p, (long long)k);
    p = (p - x) / (long long)-k;
    ans.push_back(x);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
