#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long int p, k;
  cin >> p >> k;
  while (p >= k || p < 0) {
    long long int b = 0;
    if ((k - p) % k != 0)
      b = floor((long double)(k - p) / (long double)k);
    else
      b = (k - p) / k - 1;
    ans.push_back(p + k * b), p = b;
  }
  ans.push_back(p);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
