#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
  return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int MAXN = 212345;
long long r, k;
int s[MAXN];
vector<long long> ans;
int main() {
  scanf("%lld%lld", &r, &k);
  int st = 10000000;
  while ((r >= k || r < 0) && st--) {
    long long d;
    if (r > k)
      d = -r / k;
    else
      d = -r / k + (r % k != 0);
    ans.push_back(r + d * k);
    r = d;
  }
  if (r != 0) ans.push_back(r);
  if (st <= 0) {
    puts("-1");
    return 0;
  } else {
    printf("%d\n", (int)ans.size());
    for (int a = 0; a < ans.size(); a++) {
      printf("%lld ", ans[a]);
    }
  }
}
