#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  queue<long long> s;
  while (n) {
    long long r = n % (-k);
    n /= (-k);
    if (r < 0) {
      r += k;
      n++;
    }
    s.push(r);
  }
  cout << s.size() << endl;
  while (!s.empty()) {
    cout << s.front() << " ";
    s.pop();
  }
}
