#include <bits/stdc++.h>
using namespace std;
long long p, K;
int n;
long long ans[10000011], a[10000011];
int main() {
  scanf("%lld%lld", &p, &K);
  ans[n = 0] = p % K;
  a[0] = (ans[0] - p) / K;
  if (p < K) {
    printf("%d\n%lld\n", 1, p);
    return 0;
  }
  while (n <= 10000000 && (a[n] <= 0 || a[n] >= K)) {
    n++;
    ans[n] = (a[n - 1] % K + K) % K;
    a[n] = (ans[n] - a[n - 1]) / K;
  }
  if (a[n] >= K || a[n] <= 0) {
    puts("-1");
    return 0;
  }
  n++;
  ans[n] = a[n - 1];
  printf("%d\n", n + 1);
  for (int i = 0; i <= n; i++) printf("%lld ", ans[i]);
  return 0;
}
