#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int md = 1e9 + 7;
const int N = 1e5 + 10;
int n, m;
int T;
int k;
long long p;
long long q[N];
long long ar[N];
int now = -1;
set<long long> se[N];
inline long long up(long long x, long long y) {
  long long re = x / y - 1;
  while (re * y < x) re++;
  return re;
}
inline long long down(long long x, long long y) {
  long long re = x / y + 1;
  while (re * y > x) re--;
  return re;
}
bool dfs(int x) {
  if (x >= N - 5) return 0;
  if (se[x].count(q[x])) return 0;
  se[x].insert(q[x]);
  if (0 <= q[x] && q[x] < k) {
    now = x;
    ar[0] = q[0] * k + p;
    for (int i = 0; i <= x - 1; i++) ar[i + 1] = q[i] + q[i + 1] * k;
    ar[x + 1] = q[x];
    return 1;
  }
  for (q[x + 1] = up(-q[x], k); q[x + 1] <= 1 + down(-q[x], k); q[x + 1]++) {
    if (dfs(x + 1)) return 1;
  }
  return 0;
}
void solve() {
  long long l = up(-p, k);
  long long r = 1 + down(-p, k);
  for (q[0] = l; q[0] <= r; q[0]++)
    if (dfs(0)) break;
  if (now >= 0) {
    now++;
    while (ar[now] == 0) now--;
    printf("%d\n", now + 1);
    for (int i = 0; i <= now; i++)
      printf("%I64d%c", ar[i], i == now ? 10 : ' ');
  } else {
    puts("-1");
  }
}
int main() {
  scanf("%I64d%d", &p, &k);
  solve();
  return 0;
}
