#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p, k;
  cin >> p >> k;
  long long f = 1;
  long long i = 0;
  vector<long long> a;
  long long mul = 1;
  while (1) {
    if (p == 0) break;
    if (f) {
      p /= mul;
      long long mod = p % k;
      if (mod == 0) {
        a.push_back(0);
      } else {
        long long v = mod;
        a.push_back(v);
        if (p < v) {
          cout << "-1\n";
          return 0;
        }
        p -= v;
      }
    } else {
      p /= mul;
      long long mod = p % k;
      if (mod == 0) {
        { a.push_back(0); }
      } else {
        long long v = mod;
        a.push_back(k - v);
        p += (k - v);
      }
    }
    f = !f;
    mul = k;
  }
  cout << (long long)a.size() << '\n';
  for (auto x : a) {
    cout << x << ' ';
  }
  cout << '\n';
}
