#include <bits/stdc++.h>
using namespace std;
long long ans[1000005];
int main() {
  long long p, k;
  cin >> p >> k;
  int time = 0;
  long long res = p;
  int cur = 0;
  bool cursign = 0;
  while (res != 0) {
    time++;
    if (time > 10000) {
      cout << -1 << endl;
      return 0;
    }
    if (!cursign) {
      ans[cur++] = res % k;
      res /= k;
    } else {
      ans[cur++] = (k - (res % k)) % k;
      res = (res + k - 1) / k;
    }
    cursign = !cursign;
  }
  cout << cur << endl;
  for (int i = 0; i < cur; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
