#include <bits/stdc++.h>
const int N = 2010;
int n;
int a[100];
int main() {
  long long p;
  int k;
  scanf("%lld%d", &p, &k);
  while (p) {
    a[n] = p % k;
    if (a[n] < 0) a[n] += k;
    p = (a[n] - p) / k;
    ++n;
  }
  printf("%d\n", n);
  for (int i = 0; i < n - 1; ++i) printf("%d ", a[i]);
  printf("%d\n", a[n - 1]);
  return 0;
}
