#include <bits/stdc++.h>
using namespace std;
long long p, k;
vector<int> v;
int main() {
  cin >> p >> k;
  v.push_back(p % k);
  long long a0 = -p / k;
  while (1) {
    long long a1 = -a0 / k;
    while (a1 * k + a0 < 0) a1++;
    while (a1 * k + a0 >= k) a1--;
    if (a1 < k && a1 >= 0) {
      v.push_back(a0 + k * a1);
      v.push_back(a1);
      break;
    }
    v.push_back(a0 + k * a1);
    a0 = a1;
  }
  while (v.back() == 0) v.pop_back();
  printf("%d\n", v.size());
  for (int i = 0; i < v.size(); ++i) printf("%d ", v[i]);
}
