#include <bits/stdc++.h>
using namespace std;
long long n, k;
void solve() {
  scanf("%lld %lld", &n, &k);
  vector<long long> ans;
  while (n != 0) {
    long long rem = (n % k + k) % k;
    ans.push_back(rem);
    n -= rem;
    n /= k;
    n = -n;
  }
  printf("%d\n", ans.size());
  for (long long x : ans) {
    printf("%lld ", x);
  }
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
