#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t p, k;
  cin >> p >> k;
  vector<int64_t> ans;
  while (p != 0) {
    int64_t a = ((p % k + k) % k - p) / k;
    ans.push_back(k * a + p);
    p = a;
  }
  cout << ans.size() << "\n";
  for (int64_t x : ans) cout << x << " ";
  return 0;
}
