#include <bits/stdc++.h>
using namespace std;
const int N = 1e7;
const long long INF = 2000000000000000001ll;
long long a[N + 2];
long long b[N + 2];
long long p, d;
int n;
long long s;
int main() {
  scanf("%I64d%I64d", &p, &d);
  s = INF / d * d;
  n = 0;
  a[0] = p % d;
  b[0] = (a[0] - p) / d;
  while (b[n] != 0) {
    n++;
    a[n] = (b[n - 1] + s) % d;
    b[n] = (a[n] - b[n - 1]) / d;
    if (n > N) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", n + 1);
  for (int i = 0; i <= n; i++) printf("%I64d ", a[i]);
  return 0;
}
