#include <bits/stdc++.h>
int main() {
  long long int n, i, k, x, y, p, q, a[200010], a1[200010];
  scanf("%lld%lld", &n, &k);
  x = 1;
  a[0] = n;
  while (x % 2 == 0 || n >= k) {
    if (n % k == 0) {
      a[x] = n / k;
      x++;
      n = n / k;
    } else if (x % 2 != 0) {
      a[x] = n / k;
      x++;
      n = n / k;
    } else if (x % 2 == 0) {
      a[x] = 1 + (n / k);
      x++;
      n = 1 + (n / k);
    }
  }
  y = 0;
  for (i = 1; i < x; i++) {
    a1[y] = k * a[i] - a[i - 1];
    if (a1[y] < 0) a1[y] = -a1[y];
    y++;
  }
  a1[y] = a[x - 1];
  y++;
  printf("%lld\n", y);
  for (i = 0; i < y; i++) printf("%lld ", a1[i]);
  return 0;
}
