#include <bits/stdc++.h>
using namespace std;
long long p, k;
vector<long long> res;
long long mod(long long p, long long k) {
  p %= k;
  if (p < 0) p += k;
  return p;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> p >> k;
  for (long long i = 0;; ++i) {
    long long c = 0;
    if (i % 2 == 0) {
      if (p < k) {
        res.push_back(p);
        break;
      }
      while (c < k && mod(p - c, k) != 0) ++c;
    } else
      while (c < k && mod(p + c, k) != 0) ++c;
    if (c == k) {
      cout << "-1\n";
      return 0;
    }
    res.push_back(c);
    if (i % 2 == 0)
      p = (p - c) / k;
    else
      p = (p + c) / k;
  }
  cout << res.size() << "\n";
  for (long long x : res) cout << x << " ";
  cout << "\n";
}
