#include <bits/stdc++.h>
using namespace std;
int ans[22222];
int main() {
  long long p, k;
  scanf("%I64d%I64d", &p, &k);
  int top = 0;
  while (p) {
    ans[top++] = p % k;
    p /= k;
  }
  for (int i = 0; i < top; i++) {
    if (ans[i] >= k) {
      ans[i + 1] += ans[i] / k;
      ans[i] %= k;
      if (i == top - 1) top++;
    }
    if (i & 1) {
      if (ans[i]) {
        if (i == top - 1) top++;
        ans[i + 1]++;
        ans[i] = k - ans[i];
      }
    }
  }
  printf("%d\n", top);
  for (int i = 0; i < top; i++) printf("%d ", ans[i]);
}
