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