#include <bits/stdc++.h>
using namespace std;
long long int p, k, lol, tmp, tpp, cur;
vector<long long int> vt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  scanf("%lld%lld", &p, &k);
  lol = p;
  if (lol < k) {
    printf("1\n%lld\n", p);
    return 0;
  }
  while (1) {
    tmp = abs(lol) / k;
    tpp = abs(lol) % k;
    if (tpp && lol < 0) tmp++;
    if (lol > 0)
      cur = -tmp;
    else
      cur = tmp;
    if (lol > 0)
      lol -= (tmp * k);
    else
      lol += (tmp * k);
    vt.push_back(lol);
    lol = cur;
    if (lol >= 0 && lol < k && tmp < k) {
      vt.push_back(tmp);
      break;
    } else if (lol >= 0 && lol < k && tmp >= k)
      lol = tmp;
  }
  lol = vt.size();
  printf("%lld\n", lol);
  for (int i = 0; i < lol; i++) printf("%lld ", vt[i]);
  return 0;
}
