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