#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 1;
  char ch = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  return x * f;
}
int n, cnt;
long long p, k;
int a[maxn], ans[maxn];
char c[maxn];
int main() {
  scanf("%lld%lld", &p, &k);
  int C = 1;
  while (p > 0) {
    if (C & 1) {
      ans[++cnt] = p % k, p /= k;
    } else {
      if (p % k)
        ans[++cnt] = k - p % k, p /= k, p++;
      else
        ans[++cnt] = 0, p /= k;
    }
    C++;
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; ++i) printf("%d ", ans[i]);
}
