#include <bits/stdc++.h>
using namespace std;
long long p, k;
int dep, a[2002];
int main() {
  long long t, r;
  int dep = 0;
  scanf("%lld%lld\n", &p, &k);
  while (p != 0) {
    t = p / (-k), r = p % (-k);
    if (r < 0) t++, r += k;
    p = t;
    a[++dep] = r;
  }
  printf("%d\n", dep);
  for (int i = 1; i <= dep; ++i) printf("%d ", a[i]);
  return 0;
}
