#include <bits/stdc++.h>
using namespace std;
const int maxn = 500001;
long long read() {
  char c = getchar();
  long long x = 0;
  int flag = 1;
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  x *= flag;
  return x;
}
long long term = 0;
long long p, m;
long long perm[maxn];
void wk() {
  while (perm[term] >= m || perm[term] < 0) {
    long long ans1 = perm[term] / m, ans2 = perm[term] % m;
    if (ans2 < 0) ans1--, ans2 += m;
    perm[++term] = -ans1;
    perm[term - 1] = ans2;
  }
}
int main() {
  p = read(), m = read();
  perm[0] = p;
  wk();
  printf("%lld\n", term + 1);
  for (int i = 0; i <= term; i++) {
    printf("%lld ", perm[i]);
  }
  return 0;
}
