#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long p, k;
  cin >> p >> k;
  vector<long long> a;
  while (p) {
    a.push_back(p % k);
    p /= k;
  }
  a.push_back(0);
  a.push_back(0);
  long long K = 2 * k + 1;
  vector<pair<long long, long long> > table(K * (a.size() + 1), {-1, -1});
  table[a.size() * K + k] = {0, 0};
  for (long long i = a.size() - 1; i >= 0; i--) {
    for (long long j = 0; j < K; j++) {
      if (table[(i + 1) * K + j].first < 0) continue;
      long long J = j - k;
      for (long long w = 0; w < k; w++) {
        long long W = (i % 2) ? -w : w;
        long long next = J * k + W - a[i];
        if (abs(next) > k) continue;
        table[i * K + (next + k)] = {W + k, J};
      }
    }
  }
  if (table[k].first < 0) {
    cout << "-1\n";
  } else {
    vector<long long> ans;
    long long cur = 0;
    for (long long i = 0; i < a.size(); i++) {
      auto opt = table[i * K + (cur + k)];
      ans.push_back(abs(opt.first - k));
      cur = opt.second;
    }
    while (ans.size() && ans.back() == 0) ans.pop_back();
    cout << ans.size() << "\n";
    for (long long i = 0; i < ans.size(); i++) {
      if (i) cout << " ";
      cout << ans[i];
    }
    cout << "\n";
  }
  return 0;
}
