#include <bits/stdc++.h>
using namespace std;
const long long maxn = 17;
long long p, k;
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> p >> k;
  vector<long long> ans;
  while (p) {
    long long r = p % -k;
    p /= -k;
    if (r < 0) {
      r += k;
      p += 1;
    }
    ans.push_back(r);
  }
  cout << ans.size() << '\n';
  for (auto x : ans) cout << x << ' ';
  cout << '\n';
}
