#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int main() {
  long long p;
  int k;
  cin >> p >> k;
  if (p < k) {
    cout << 1 << endl << p;
    return 0;
  }
  long long last = -p / k;
  ans.push_back(p % k);
  while (1) {
    if (last >= 0 && last < k) break;
    long long tmp;
    if (last < 0) {
      tmp = (-last + k - 1) / k;
    } else {
      tmp = -last / k;
    }
    ans.push_back(tmp * k + last);
    last = tmp;
  }
  ans.push_back(last);
  cout << ans.size() << endl;
  for (int x : ans) {
    printf("%d ", x);
  }
  return 0;
}
