#include <bits/stdc++.h>
using namespace std;
long long p, k;
int n;
long long a[100010];
long long b[100010];
int main() {
  scanf("%I64d%I64d", &p, &k);
  a[0] = -p / k;
  while (a[n]) {
    n++;
    if (a[n - 1] > 0)
      a[n] = -a[n - 1] / k;
    else
      a[n] = -a[n - 1] / k + (a[n - 1] % k != 0);
    if (n >= 100000) {
      puts("-1");
      return 0;
    }
  }
  b[0] = p + a[0] * k;
  for (int i = 1; i <= n; i++) b[i] = a[i] * k + a[i - 1];
  printf("%d\n", n + 1);
  for (int i = 0; i <= n; i++) printf("%d ", b[i]);
  printf("\n");
  return 0;
}
