#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> ans;
  while (n != 0) {
    long long d = n % (-k);
    n /= -k;
    if (d < 0) {
      d += k;
      n++;
    }
    ans.push_back(d);
  }
  cout << ans.size() << "\n";
  for (long long a : ans) cout << a << " ";
}
