#include <bits/stdc++.h>
using namespace std;
;
void solve() {
  long long p, k;
  cin >> p >> k;
  if (p < k) {
    cout << 1 << '\n';
    cout << p << '\n';
    return;
  }
  vector<long long> v;
  v.push_back(p / k);
  for (long long i = 1;; i++) {
    long long temp = v[i - 1] / k;
    if ((temp * k != v[i - 1]) && (i % 2)) {
      temp++;
    }
    v.push_back(temp);
    if ((temp < k) && (i % 2)) {
      if (temp == 0) {
        cout << -1 << '\n';
        return;
      }
      break;
    }
  }
  cout << (long long)((v).size()) + 1 << '\n';
  cout << p - v[0] * k << " ";
  for (long long i = 1; i < (long long)((v).size()); i++) {
    if (i % 2) {
      cout << -v[i - 1] + v[i] * k << " ";
    } else
      cout << v[i - 1] - v[i] * k << " ";
  }
  cout << v[(long long)((v).size()) - 1] << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  clock_t start, end;
  start = clock();
  cout << fixed << setprecision(20);
  while (t--) {
    solve();
  }
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
}
