#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long int p, k;
  cin >> p >> k;
  vector<long long int> v;
  int d = 0;
  while (p != 0) {
    long long int r = p % (-k);
    if (r < 0) {
      r += k;
    }
    v.push_back(r);
    p = (p - r) / (-k);
    ++d;
  }
  cout << d << endl;
  for (int i = 0; i < d; ++i) {
    cout << v[i] << ' ';
  }
  cout << endl;
  return 0;
}
