#include <bits/stdc++.h>
using namespace std;
int main() {
  long long arr[500];
  int d;
  long long p, k;
  while (cin >> p >> k) {
    memset(arr, 0, sizeof(arr));
    arr[0] = p;
    for (d = 0; arr[d]; d++) {
      arr[d + 1] = arr[d] / k;
      arr[d] %= k;
      if (d % 2 && arr[d]) {
        arr[d + 1]++;
        arr[d] = k - arr[d];
      }
    }
    cout << d << endl;
    for (int i = 0; i < d; i++) {
      cout << arr[i];
      if (i < d - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}
