#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p, k;
  cin >> p >> k;
  vector<long long> ans;
  for (long long i = 0;; i++) {
    long long q = -(p / k);
    if (p < 0) q = (k - 1 - p) / k;
    long long res = q * k + p;
    if (res == 0 && q == 0) break;
    ans.push_back(res);
    p = q;
  }
  cout << ans.size() << endl;
  for (auto x : ans) cout << x << " ";
}
