#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p;
  int k;
  cin >> p >> k;
  vector<int> ans;
  while (p != 0) {
    if (p % k != 0) {
      int c = (p % k + k) % k;
      ans.push_back(c);
      p -= c;
    } else
      ans.push_back(0);
    p /= -k;
  }
  cout << ans.size() << "\n";
  for (auto i : ans) cout << i << ' ';
  return 0;
}
