#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
using namespace std;
int main() {
  long long p, k;
  cin >> p >> k;
  long long cur = 1;
  vector<long long> res;
  while (p) {
    if (cur < 0)
      res.push_back((k - p % k) % k);
    else
      res.push_back(p % k);
    if (cur < 0 && p % k != 0) {
      p += k - (p % k);
    }
    p /= k;
    cur *= -1;
  }
  cout << (int)res.size() << endl;
  for (int i = 0; i < (int)res.size(); i++) cout << res[i] << ' ';
  cout << endl;
  return 0;
}
