#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  long long P;
  int K;
  cin >> P >> K;
  K = -K;
  vector<int> answer;
  while (P != 0) {
    int r = P % K;
    if (r < 0) {
      r += -K;
    }
    P -= r;
    answer.push_back(r);
    P /= K;
  }
  cout << answer.size() << endl;
  for (int i = 0; i < answer.size(); i++) {
    cout << answer[i] << " \n"[i == answer.size() - 1];
  }
  return 0;
}
