#include <bits/stdc++.h>
using namespace std;
long long p, k;
vector<long long> ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> p >> k;
  while (p) {
    long long q = -p / k;
    long long r = p + q * k;
    if (r < 0) {
      r += k;
      q++;
    }
    ans.push_back(r);
    p = q;
  }
  cout << (long long)ans.size() << "\n";
  for (auto it : ans) cout << it << " ";
}
