#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  if (f) x = -x;
  return x;
}
int a[100005], cnt = 0;
long long p, n, x[2005];
int main() {
  int i, j, k;
  scanf("%lld%lld", &p, &n);
  long long las = p;
  for (i = 0;; i++) {
    x[i] = -las / n;
    while (x[i] * n + las < 0) x[i]++;
    while (x[i] * n + las >= n) x[i]--;
    las = x[i];
    if (!las) {
      printf("%d\n", i + 1);
      long long las = p;
      for (j = 0; j <= i; j++) {
        printf("%lld ", x[j] * n + las);
        las = x[j];
      }
      return 0;
    }
  }
  return 0;
}
