#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const long long N = 500007;
long long res[N];
int main() {
  long long p = read(), k = read();
  long long ans = 0, flag = 0;
  while (p) {
    ans++;
    if (flag) {
      res[ans] = (!(p % k)) ? 0 : (k - p % k);
      p = (p - 1) / k + 1;
    } else {
      res[ans] = p % k;
      p /= k;
    }
    flag ^= 1;
  }
  printf("%I64d\n", ans);
  for (long long i = 1; i <= ans; i++) printf("%I64d ", res[i]);
}
