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