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