#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  ll p, k;
  cin >> p >> k;
  vector<int> d;
  while (p < 0 || p >= k) {
    ll a = ((p % k) + k) % k;
    d.push_back(a);
    p = (a - p) / k;
    if (d.size() > 5000000) {
      cout << -1 << "\n";
      return 0;
    }
  }
  d.push_back(p);
  cout << d.size() << "\n";
  for (int x : d) cout << x << " ";
  cout << "\n";
  return 0;
}
