#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1LL;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
template <class T>
inline void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void chmin(T &a, T b) {
  if (a > b) a = b;
}
inline void swap(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}
using namespace std;
long long a[5010];
long long p, k;
int main() {
  scanf("%lld%lld", &p, &k);
  for (int i = (0); i <= (233); ++i) a[i] = p;
  int cur = 0;
  while (a[cur] < 0 || a[cur] >= k) {
    long long fc = a[cur] / k, c = a[cur] % k;
    fc -= (c < 0);
    if (c < 0) c += k;
    a[cur + 1] = -fc;
    a[cur] = c;
    ++cur;
  }
  cout << cur + 1 << endl;
  for (int i = (0); i <= (cur); ++i) cout << a[i] << " ";
  puts("");
  return 0;
}
