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