#include <bits/stdc++.h>
using namespace std;
long long p, k;
vector<long long> a;
int main() {
  cin >> p >> k;
  while (true) {
    a.push_back(p % k);
    p = (p - p % k) / k;
    if (p == 0) break;
    if (p % k == 0) {
      a.push_back(0);
      p = p / k;
    } else {
      a.push_back(k - p % k);
      p = ((p + k - p % k) / k);
    }
  }
  cout << a.size() << endl;
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << " ";
  }
}
