#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p, k, ans[1000] = {0}, i = 0;
  cin >> p >> k;
  while (p) {
    i++;
    ans[i] = (p % k < 0 ? (p % k + k) % k : p % k);
    p -= ans[i];
    p /= (-k);
  }
  cout << i << endl;
  for (int j = 1; j <= i; j++) cout << ans[j] << " ";
  cout << endl;
  return 0;
}
