#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
  long long p, k;
  cin >> p >> k;
  for (int i = 0; i < 100000; i++) {
    if (p == 0) break;
    long long rem = (p % k);
    p /= k;
    if (rem == 0) {
      v.push_back(0);
      continue;
    }
    if (i % 2) {
      p++;
      rem = k - rem;
    }
    v.push_back(rem);
  }
  int sz = v.size();
  cout << sz << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
