#include <bits/stdc++.h>
using namespace std;
long long p;
int k;
long long q[10000];
int f[10000];
int main() {
  scanf("%I64d%d", &p, &k);
  int len = 0;
  f[0] = k;
  while (p < 0 || p >= k) {
    ++len;
    if (p > 0)
      q[len] = -p / k;
    else
      q[len] = -(p - k + 1) / k;
    f[len - 1] = p + q[len] * k;
    p = q[len];
  }
  f[len] = p;
  printf("%d\n", len + 1);
  for (int i = 0; i <= len; ++i) printf("%d ", f[i]);
  return 0;
}
