#include <bits/stdc++.h>
using namespace std;
long long p, k, ok;
map<long long, int> vis;
vector<int> a;
inline int gi() {
  register int x = 0, q = 1;
  register char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') q = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q * x;
}
inline void work() {
  register int lim = 100000000;
  while (p != 0) {
    if (vis.count(p) || a.size() > lim) {
      ok = 1;
      return;
    }
    vis[p] = 1;
    register long long ret = -p / k;
    if (ret * k + p >= k) ret--;
    if (ret * k + p < 0) ret++;
    a.push_back(ret * k + p), p = ret;
  }
  return;
}
int main() {
  cin >> p >> k;
  work();
  if (ok) puts("-1"), exit(0);
  cout << a.size() << endl;
  for (register int i = 0, S = a.size(); i < S; i++) printf("%d ", a[i]);
  return 0;
}
