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