#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
double inff = 1.0 / 0.0;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long int x, y, n, i, z, j, k, w, u, q, t, c, p, m;
vector<long long int> v;
long long int div1(long long int x, long long int y) {
  if (x < 0 and y < 0) {
    return (llabs(y) + llabs(x) - 1) / llabs(x);
  } else {
    return (-1) * (llabs(y) / llabs(x));
  }
}
long long int mod(long long int x, long long int y) {
  if (x < 0 and y < 0) {
    w = (llabs(y) / llabs(x) + 1) * llabs(x);
    w -= llabs(y);
    return w % llabs(x);
  } else {
    return llabs(y) % llabs(x);
  }
}
void solve() {
  cin >> p >> k;
  k = (-1) * k;
  while (p != 0) {
    v.push_back(mod(k, p));
    p = div1(k, p);
  }
  cout << v.size() << "\n";
  for (auto a : v) {
    cout << a << " ";
  }
}
int main() {
  t = 1;
  while (t--) {
    solve();
  }
}
