#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m;
  cin >> n >> m;
  m *= -1;
  vector<long long int> v;
  while (n) {
    long long int r = n % m;
    n = n / m;
    if (r < 0) {
      r -= m;
      n += 1;
    }
    v.emplace_back(r);
  }
  cout << v.size() << endl;
  for (__typeof(v.size()) i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
