#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int p, k;
  cin >> p >> k;
  vector<long long int> res;
  long long int prev = p;
  while (1) {
    long long int cur_a;
    if (-prev < 0) {
      cur_a = -prev / k;
    } else {
      cur_a = (-prev + k - 1ll) / k;
    }
    long long int term = cur_a * k + prev;
    if (term < 0 || term >= k) {
      cout << "-1"
           << "\n";
      return 0;
    }
    if (cur_a == 0 && term == 0) {
      break;
    }
    res.push_back(term);
    prev = cur_a;
  }
  cout << res.size() << "\n";
  for (auto it : res) {
    cout << it << " ";
  }
  cout << "\n";
}
