#include <bits/stdc++.h>
using namespace std;
long long mod(long long a, long long b) {
  a -= a / b * b;
  if (a < 0) a += abs(b);
  return a;
}
int main() {
  long long p, n;
  cin >> p >> n;
  long long new_p = p;
  vector<long long> v;
  while (new_p != 0) {
    long long x = mod(new_p, -n);
    v.push_back(x);
    new_p = (new_p - x) / (-n);
  }
  cout << v.size() << endl;
  for (long long i : v) cout << i << " ";
}
