#include <bits/stdc++.h>
using namespace std;
int const MAXN = (int)2e6 + 1, INF = (int)1e9 + 1, MOD = (int)1e9 + 7;
long long pos, n, k, cur;
bool ok1, ok2;
long long power(int e, int r) {
  long long art = 1;
  for (int i = 1; i <= r; i++) art *= e;
  return art;
}
int q, a[MAXN], b[MAXN], m, ans;
bool used[MAXN];
string second;
vector<int> v;
int main() {
  long long p;
  cin >> p >> k;
  while (p != 0) {
    int x = p % (-k);
    p /= (-k);
    if (x < 0) {
      x += k;
      p++;
    }
    v.push_back(x);
  }
  cout << v.size() << endl;
  for (auto i : v) cout << i << " ";
  return 0;
}
