#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
  long long int n, m, c = 0, ar[100000];
  scanf("%I64d %I64d", &n, &m);
  m = -m;
  while (n != 0) {
    if (n % m < 0) {
      ar[c] = n % m - m;
      n = n / m + 1;
    } else {
      ar[c] = n % m;
      n = n / m;
    }
    c++;
  }
  printf("%I64d\n", c);
  for (int i = 0; i < c; ++i) {
    printf("%I64d ", ar[i]);
  }
  printf("\n");
  return 0;
}
