#include <bits/stdc++.h>
using namespace std;
long long a[2333];
int main() {
  long long p, k, w = 0;
  cin >> a[0] >> k;
  p = a[0];
  for (int i = 1; p; i++) {
    if (p < 0)
      a[i] = (-p + k - 1) / k;
    else
      a[i] = -(p / k);
    p = a[i];
    w = i;
  }
  cout << w << endl;
  for (int i = 0; i < w; i++) cout << a[i] + a[i + 1] * k << ' ';
  return 0;
}
