#include <bits/stdc++.h>
using namespace std;
long long q[10000010], ans[10000010];
int main() {
  long long p, k;
  scanf("%lld%lld", &p, &k);
  q[0] = -p / k;
  ans[0] = p % k;
  int maxd = 0;
  bool no_sol = false;
  if (q[0] >= k || q[0] < 0) {
    for (int d = 1; !no_sol; d++) {
      maxd = d;
      if (q[d - 1] < 0) {
        q[d] = (k - 1 - q[d - 1]) / k;
      } else {
        q[d] = -q[d - 1] / k;
      }
      ans[d] = q[d - 1] + q[d] * k;
      if (ans[d] >= k)
        no_sol = true;
      else if (q[d] < k && q[d] >= 0) {
        break;
      }
    }
  } else {
    puts("1");
    printf("%lld\n", ans[0]);
    exit(0);
  }
  if (no_sol)
    puts("-1");
  else {
    printf("%d\n", maxd + 2);
    ans[maxd + 1] = q[maxd];
    for (int i = 0; i <= maxd + 1; i++) printf("%lld ", ans[i]);
    puts("");
  }
  return 0;
}
