#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long p;
  int k;
  cin >> p >> k;
  long long pi = p;
  vector<int> ans;
  while (!(pi >= 0 && pi < k)) {
    long long mi = (pi < 0 ? (pi - k + 1) / k : pi / k);
    long long ai = pi - k * mi;
    ans.push_back(ai);
    pi = -mi;
  }
  if (pi) ans.push_back(pi);
  cout << ans.size() << '\n';
  for (long long a : ans) cout << a << ' ';
  cout << '\n';
  return 0;
}
