#include <bits/stdc++.h>
std::vector<long long> ans;
long long fix(long long x, long long y) { return (x % y + y) % y; }
void solve(long long K, long long P) {
  if (P != 0) {
    ans.push_back(fix(P, K));
    solve(K, (fix(P, K) - P) / K);
  }
}
int main() {
  long long P, K;
  scanf("%lld%lld", &P, &K);
  solve(K, P);
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%lld%c", ans[i], " \n"[i == ans.size() - 1]);
  return 0;
}
