#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long t = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') t = t * 10 + c - 48, c = getchar();
  return t * f;
}
long long tot = 0;
long long p, m, Ans[500001];
int main() {
  p = read(), m = read();
  Ans[0] = p;
  while (Ans[tot] >= m || Ans[tot] < 0) {
    long long ans1 = Ans[tot] / m, ans2 = Ans[tot] % m;
    if (ans2 < 0) ans1--, ans2 += m;
    Ans[++tot] = -ans1;
    Ans[tot - 1] = ans2;
  }
  printf("%I64d\n", tot + 1);
  for (register long long i = 0; i <= tot; ++i) printf("%I64d ", Ans[i]);
  return 0;
}
