#include <bits/stdc++.h>
using namespace std;
long long p, k;
long long C[25000];
long long Q[25000];
long long Pp[25000];
long long d;
long long Div(long long D, long long d) {
  if (D >= 0) return D / d;
  if (D % d == 0) return D / d;
  return D / d - 1LL;
}
long long solve(long long P) {
  Q[d] = -1LL * Div(P, k);
  C[d] = k * Q[d] + P;
  Pp[d] = P;
  d++;
  return Q[d - 1LL];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> p >> k;
  while ((p < 0 || p >= k) && d <= 24000LL) {
    p = solve(p);
  }
  if (d < 24000LL) {
    cout << d + 1 << "\n";
    for (long long i = 0LL; i < d; i++) cout << C[i] << " ";
    cout << p << "\n";
  } else
    cout << -1 << "\n";
  return 0;
}
