#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
vector<long long> ans;
int main() {
  long long p, k;
  scanf("%lld %lld", &p, &k);
  while (p != 0) {
    long long rem = p % k;
    while (rem < 0) rem += k, p += -k;
    ans.push_back(rem);
    p /= -k;
  }
  int len = ans.size();
  printf("%d\n", len);
  for (int i = 0; i < len; i++) printf("%lld ", ans[i]);
}
