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