#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn];
long long ans[maxn];
long long k, p;
long long get(long long a1, int i) {
  ans[i] = ((a1 % k) + k) % k;
  return (ans[i] - a1) / k;
}
int main() {
  cin >> p >> k;
  a[0] = p;
  int i;
  for (i = 1; i < maxn; i++) {
    a[i] = get(a[i - 1], i);
    if (a[i] == 0) break;
  }
  cout << i << endl;
  for (int j = 1; j <= i; j++) {
    cout << ans[j] << " ";
  }
  cout << endl;
  return 0;
}
