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