#include <bits/stdc++.h>
using namespace std;
long long p;
int k;
int cnt = 0;
int ans[107];
int get() { return (p % k + k) % k; }
int main() {
  while (~scanf("%lld%d", &p, &k)) {
    cnt = 0;
    while (p != 0) {
      ++cnt;
      ans[cnt] = get();
      p -= get();
      p /= (-k);
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
    printf("\n");
  }
  return 0;
}
