#include <bits/stdc++.h>
using namespace std;
int a[20010];
int main() {
  long long p, k;
  while (~scanf("%lld%lld", &p, &k)) {
    int l = 0;
    while (p >= k || p < 0) {
      if (p < 0) {
        long long tmp = (-p) / k;
        a[l] = tmp * k + p;
        if (a[l] < 0) tmp++, a[l] += k;
        p = tmp;
      } else {
        long long tmp = p / k;
        tmp = -tmp;
        a[l] = p % k;
        p = tmp;
      }
      l++;
    }
    a[l++] = p;
    while (l > 1 && a[l - 1] == 0) l--;
    if (p < 0 || p >= k)
      puts("-1");
    else {
      printf("%d\n", l);
      for (int i = 0; i < l; i++) printf("%d%c", a[i], " \n"[i == l - 1]);
    }
  }
}
