#include <bits/stdc++.h>
template <typename tp>
inline tp max(tp x, tp y) {
  return (x > y) ? x : y;
}
template <typename tp>
inline tp min(tp x, tp y) {
  return (x < y) ? x : y;
}
template <typename tp>
inline bool chkmax(tp& x, tp y) {
  return (x >= y) ? false : (x = y, true);
}
template <typename tp>
inline bool chkmin(tp& x, tp y) {
  return (x <= y) ? false : (x = y, true);
}
template <typename tp>
tp read(tp& in) {
  in = 0;
  char ch = getchar();
  tp f = 1;
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) in = in * 10 + ch - '0';
  return in *= f;
}
static const int max1 = 1000000 + 11;
long long p;
long long k;
long long ai[max1], bi[max1];
int main() {
  read(p), read(k);
  ai[0] = p % k, bi[0] = -p / k;
  if (!bi[0]) {
    puts("1");
    printf("%I64d\n", ai[0]);
    return 0;
  }
  for (int i = (1), ir = (1000000); i <= (ir); ++i) {
    assert(bi[i - 1]);
    if (bi[i - 1] >= 0 && bi[i - 1] < k) {
      ai[i] = bi[i - 1];
      printf("%d\n", i + 1);
      for (int j = (0), jr = (i); j <= (jr); ++j) printf("%I64d ", ai[j]);
      putchar(10);
      return 0;
    }
    if (bi[i - 1] < 0) {
      bi[i] = -bi[i - 1] / k + (bi[i - 1] % k != 0);
      ai[i] = bi[i - 1] + k * bi[i];
      assert(ai[i] >= 0 && ai[i] < k);
    } else {
      ai[i] = bi[i - 1] % k, bi[i] = -bi[i - 1] / k;
    }
  }
  puts("-1");
  return 0;
}
