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