#include <bits/stdc++.h>
long long p;
int k;
namespace solver1 {
void main() {
  std::vector<int> ans;
  int i;
  for (i = 0; p; i++) {
    if (i & 1)
      ans.push_back(((p - 1) / k + 1) * k - p), p = (p - 1) / k + 1;
    else
      ans.push_back(p % k), p /= k;
  }
  printf("%d\n", (int)ans.size());
  for (auto i : ans) {
    printf("%d ", i);
  }
  printf("\n");
}
}  // namespace solver1
int main() {
  std::cin >> p >> k;
  solver1::main();
}
