#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long p, k;
  cin >> p >> k;
  vector<long long> a;
  a.push_back(p);
  while (true) {
    long long x = ceil((double)-a.back() / k);
    a.push_back(x);
    if (x == 0) break;
  }
  vector<long long> b(a.size() - 1);
  for (long long i = 1; i < a.size(); i++) {
    b[i - 1] = (k * a[i]) + (i == 0 ? 0 : a[i - 1]);
  }
  cout << a.size() - 1 << "\n";
  for (auto x : b) {
    cout << x << " ";
  }
  cout << "\n";
  return 0;
}
