#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 1e9 + 7;
long long ans[N];
int main() {
  long long p, k;
  cin >> p >> k;
  long long tmp = -k;
  long long idx = 0;
  while (p != 0) {
    long long rem = p % tmp;
    p /= tmp;
    if (rem < 0) rem += k, p++;
    ans[idx] = rem;
    idx++;
  }
  cout << idx << endl;
  for (int i = 0; i < idx; i++) {
    cout << ans[i] << " ";
  }
}
