#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int p, k;
  cin >> p >> k;
  vector<long long int> coefficients;
  int sgn = 1;
  while (p > 0 && coefficients.size() < 1000) {
    long long int a;
    if (sgn == 1) {
      a = (p % k);
      coefficients.push_back(a);
      p -= a;
      p /= k;
    } else {
      a = -(p % k);
      if (a == 0) a = -k;
      a = k + a;
      coefficients.push_back(a);
      p += a;
      p /= k;
    }
    sgn = 1 - sgn;
  }
  if (coefficients.size() >= 1000) {
    cout << -1 << endl;
  } else {
    cout << coefficients.size() << endl;
    for (int i = 0; i < coefficients.size(); i++) {
      cout << coefficients[i] << " ";
    }
  }
  return 0;
}
