#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main() {
  long long p, k, t, a;
  cin >> p >> k;
  while (p) {
    t = -p / k;
    while (k * t < -p) t++;
    vec.push_back(k * t + p);
    if (k * t > k - p) {
      puts("-1");
      return 0;
    }
    p = t;
  }
  printf("%d\n", vec.size());
  for (int i = 0; i < vec.size(); ++i) {
    printf("%d ", vec[i]);
  }
  return 0;
}
