#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
struct Edge {
  int from, to;
  long long weight;
  bool operator<(const Edge& obj) const { return weight < obj.weight; }
  bool operator>(const Edge& obj) const { return weight > obj.weight; }
};
signed main() {
  long long p, k;
  cin >> p >> k;
  vector<long long> out;
  while (p) {
    long long ne = (p % k + k) % k;
    out.push_back(ne);
    p -= ne;
    p /= -k;
  }
  cout << out.size() << endl;
  for (int i = (0); (out.size()) > i; i++) {
    cout << out[i];
    if (i != out.size() - 1) cout << " ";
  }
  cout << endl;
  return 0;
}
