#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& arr) {
  for (auto& i : arr) {
    in >> i;
  }
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> arr) {
  for (int64_t i = 0; i < (int64_t)arr.size() - 1; ++i) out << arr[i] << " ";
  if (arr.size()) out << arr.back();
  out << '\n';
  return out;
}
int64_t get(int64_t n, int64_t k) {
  if (n >= 0) {
    return -n / k;
  } else {
    return abs(n) / k + (n % k != 0) * 1;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t p, k;
  cin >> p >> k;
  if (p < k) {
    cout << 1 << '\n';
    cout << p << '\n';
    return 0;
  }
  vector<int64_t> ans(500000);
  ans[0] = -p / k;
  for (int64_t i = 1; i < 500000; ++i) {
    ans[i] = get(ans[i - 1], k);
  }
  if (ans.back() != 0) {
    cout << -1 << '\n';
    return 0;
  }
  while (ans.back() == 0) ans.pop_back();
  vector<int64_t> ans2(ans.size() + 1);
  ans2[0] = ans[0] * k + p;
  for (int64_t i = 1; i < ans.size(); ++i) {
    ans2[i] = ans[i] * k + ans[i - 1];
  }
  ans2[ans.size()] = ans.back();
  cout << ans2.size() << '\n';
  cout << ans2 << '\n';
  return 0;
}
