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