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