#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int main() {
  ios::sync_with_stdio(false);
  long long p;
  int k;
  cin >> p >> k;
  while (p) {
    int x = p % k;
    if (x < 0) x += k;
    ans.push_back(x);
    p -= x;
    p /= k;
    p *= -1;
  }
  cout << ans.size() << endl;
  for (auto v : ans) cout << v << " ";
  return 0;
}
