#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T a) {
  return a * a;
};
template <typename T>
void dprint(T begin, T end) {
  for (auto i = begin; i != end; i++) cerr << (*i) << " ";
  cerr << "\n";
};
long long p, k;
vector<long long> v;
int main() {
  cin >> p >> k;
  while (p) {
    if (p % (-k) < 0) {
      v.push_back(p % (-k) + k);
      p = p / (-k) + 1;
    } else {
      v.push_back(p % (-k));
      p /= (-k);
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < ((int)v.size()); i++) cout << v[i] << " ";
  cout << endl;
  return 0;
}
