#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int k, p;
  vector<int> ans;
  cin >> p >> k;
  long long int c;
  long long int s = 0;
  while (p != 0) {
    c = p % k;
    if (c < 0) c += k;
    p = (c - p) / k;
    ans.push_back(c);
    s++;
  }
  cout << s << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << ' ';
  }
}
