#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t P, K;
  cin >> P >> K;
  vector<int> ans;
  while (true) {
    int64_t P2;
    if (P > 0) {
      P2 = -(P / K);
    } else {
      P2 = (abs(P) + K - 1) / K;
    }
    ans.push_back(K * P2 + P);
    if (P2 == 0) break;
    P = P2;
  }
  cout << ans.size() << endl;
  for (int a : ans) cout << a << " ";
  cout << endl;
  return 0;
}
