#include <bits/stdc++.h>
using namespace std;
int k, t, a[1000];
long long m;
int main() {
  scanf("%lld%d", &m, &k);
  k = -k;
  while (m) a[t++] = m % k, m /= k;
  k = -k;
  for (int i = 0; i < t; ++i) {
    while (a[i] < 0) ++a[i + 1], a[i] += k;
    while (a[i] >= k) --a[i + 1], a[i] -= k;
  }
  while (a[t]) {
    while (a[t] < 0) ++a[t + 1], a[t] += k;
    while (a[t] >= k) --a[t + 1], a[t] -= k;
    ++t;
  }
  printf("%d\n", t);
  for (int i = 0; i < t; ++i) printf("%d ", a[i]);
  return 0;
}
