#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
vector<long long> ans;
int main() {
  long long p, k;
  cin >> p >> k;
  while (p) {
    long long a = p % k;
    p /= k;
    p = -p;
    if (a < 0) {
      a += k;
      p++;
    }
    ans.push_back(a);
  }
  int cnt = ans.size();
  cout << cnt << endl;
  for (int i = 0; i < cnt - 1; i++) cout << ans[i] << " ";
  cout << ans[cnt - 1] << endl;
  return 0;
}
