#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll p, k, cnt = 0;
  cin >> p >> k;
  vector<ll> res;
  while (p < 0 || k <= p) {
    ll t = (p % k + k) % k;
    res.push_back(t);
    p -= t;
    p = -p / k;
    cnt++;
    if (cnt >= 30000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  res.push_back(p);
  cout << res.size() << endl;
  for (int i = 0; i < (int)res.size(); i++) {
    cout << res[i] << " \n"[i + 1 == (int)res.size()];
  }
  return 0;
}
