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