#include <bits/stdc++.h>
using namespace std;
const long long N = 111;
long long ans[N];
long long coef[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  cout << fixed;
  long long p, k;
  cin >> p >> k;
  long long pp = p;
  long long aux = 0;
  while (true) {
    if (aux % 2 == 1) {
      p = p / k + (p % k != 0 ? 1 : 0);
      coef[aux] = p;
    } else {
      p = p / k;
      coef[aux] = -p;
    }
    aux++;
    if (p == 0) {
      break;
    }
    if (aux > 100) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << aux << endl;
  for (long long i = 0; i < aux; i++) {
    if (i == 0) {
      ans[i] = coef[i] * k + pp;
    } else {
      ans[i] = coef[i] * k + coef[i - 1];
    }
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
