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