#include <bits/stdc++.h>
int answer[128];
int main() {
  long long p;
  int k;
  scanf("%I64d%d", &p, &k);
  int d = 0;
  for (d = 0; p; d++) {
    answer[d] = p % k;
    if (answer[d] < 0) {
      answer[d] += k;
    }
    p -= answer[d];
    p /= (-k);
  }
  printf("%d\n", d);
  for (int i = 0; i < d; i++) {
    printf("%d", answer[i]);
    if (i == d - 1) {
      putchar('\n');
    } else {
      putchar(' ');
    }
  }
  return 0;
}
