#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p, k;
  while (~scanf("%lld %lld", &p, &k)) {
    long long cnst = p, coeff, cur_fx;
    vector<long long> ans;
    if (k > p) {
      puts("1");
      printf("%lld\n", p);
    } else {
      while (1) {
        coeff = -cnst / k;
        if (cnst < 0 && cnst % k) coeff++;
        cur_fx = coeff * k + cnst;
        ans.push_back(cur_fx);
        cnst = coeff;
        if (coeff < k && coeff > 0) {
          ans.push_back(coeff);
          break;
        }
      }
      printf("%d\n", (int)ans.size());
      for (long long i : ans) {
        printf("%lld ", i);
      }
      puts("");
    }
  }
  return 0;
}
