#include <bits/stdc++.h>
using namespace std;
long long n, k, a[20005], ans[20005];
long long get(long long a1, int i) {
  ans[i] = ((a1 % k) + k) % k;
  return (ans[i] - a1) / k;
}
int main() {
  cin >> n >> k;
  a[0] = n;
  for (int i = 1; i < 20005; i++) {
    a[i] = get(a[i - 1], i);
    if (!a[i]) {
      cout << i << endl;
      for (int j = 1; j <= i; j++) cout << ans[j] << " ";
      cout << endl;
      break;
    }
  }
  return 0;
}
