#include <bits/stdc++.h>
using namespace std;
template <typename T>
using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const pair<A, B>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
  return _out(s, begin(c), end(c));
}
bool debug = 0;
template <typename T>
void DEBUG(const T& x) {
  if (debug) cerr << x;
}
template <typename T, typename... Args>
void DEBUG(const T& head, const Args&... tail) {
  if (debug) {
    cerr << head;
    DEBUG(tail...);
  }
}
long long k;
void go(long long, vector<long long>&);
int main(int argc, char* argv[]) {
  if (argc > 1 and string(argv[1]) == "-D") debug = 1;
  if (!debug) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
  long long p;
  cin >> p >> k;
  vector<long long> coe;
  go(p, coe);
  if (debug)
    cerr << __PRETTY_FUNCTION__ << ":" << 69 << " - "
         << "coe"
         << "=" << coe << '\n';
  vector<long long> ans((int)(coe.size()) + 1);
  for (int i = 0; i < (int)(coe.size()); i++) {
    ans[i] = coe[i] * k;
  }
  for (int i = 1; i <= (int)(coe.size()); i++) {
    ans[i] += coe[i - 1];
  }
  ans[0] += p;
  cout << (int)(coe.size()) + 1 << '\n';
  for (int i = 0; i <= (int)(coe.size()); i++) {
    cout << ans[i] << " \n"[i == (int)(coe.size())];
  }
  return 0;
}
void go(long long a, vector<long long>& ret) {
  if (0 <= a and a < k) return;
  long long ll = -(a + k - 1) / k, rr;
  while (0 > ll * k + a or ll * k + a >= k) ll++;
  {
    long long l = ll - 1, r = 1LL << 60;
    while (r - l > 1) {
      long long mid = (l + r) >> 1;
      if ((long double)mid * k + a < k)
        l = mid;
      else
        r = mid;
    }
    rr = l;
  }
  if (rr < 0) {
    ret.push_back(rr);
    go(rr, ret);
  } else if (ll > 0) {
    ret.push_back(ll);
    go(ll, ret);
  }
}
