#include <bits/stdc++.h>
using namespace std;
const int Inf = (int)1e9 + 7;
namespace {
void solve() {
  long long p, k;
  cin >> p >> k;
  vector<long long> res;
  long long x = p;
  while (true) {
    long long d = x / (-k);
    long long r = x - d * (-k);
    if (r < 0) {
      d += (d >= 0 ? 1 : -1);
      r += k;
    }
    x = d;
    res.emplace_back(r);
    if (x >= 0 && x < k) {
      if (x > 0) res.emplace_back(x);
      break;
    }
  }
  cout << res.size() << "\n";
  for (auto e : res) cout << e << " ";
  cout << "\n";
}
}  // namespace
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(9);
  cout << fixed;
  solve();
  return 0;
}
