#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long double p, k;
  cin >> p >> k;
  vector<long double> store;
  store.push_back(p);
  long long temp = p;
  while (temp != 0) {
    temp = floor(store[store.size() - 1] / k);
    if (temp == 0) {
      break;
    }
    store.push_back(-1 * temp);
  }
  int siz = store.size();
  cout << siz << endl;
  vector<long long> final;
  for (int i = 0; i < siz - 1; i++) {
    final.push_back(k * store[i + 1] + store[i]);
  }
  final.push_back(store[siz - 1]);
  for (int i = 0; i < siz; i++) {
    cout << final[i] << " ";
  }
}
