#include <bits/stdc++.h>
using namespace std;
long long p;
int k;
int main() {
  cin >> p >> k;
  k = -k;
  queue<int> ans;
  while (p) {
    int tmp = p % k;
    p /= k;
    if (tmp < 0) {
      tmp -= k;
      ++p;
    }
    ans.push(tmp);
  }
  cout << ans.size() << endl;
  while (!ans.empty()) {
    cout << ans.front() << " ";
    ans.pop();
  }
  cout << endl;
  return 0;
}
