#include <bits/stdc++.h>
using namespace std;
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
vector<int> v;
int main() {
  long long p, k;
  scanf("%lld%lld", &p, &k);
  while (p) {
    int rem = p % -k;
    p /= -k;
    if (rem < 0) {
      p++;
      rem += k;
    }
    v.push_back(rem);
  }
  printf("%d\n", v.size());
  for (auto i : v) {
    printf("%d ", i);
  }
  puts("");
}
