#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using db = double;
using pii = pair<int, int>;
ll p, k;
set<ll> s;
vector<ll> a;
ll DIV(ll a, ll b) { return (a < 0 ? a - b + 1 : a) / b; }
int main() {
  cin >> p >> k;
  while (p) {
    ll d = DIV(p, k);
    a.push_back(p - d * k);
    p = -d;
    if (s.count(p)) {
      puts("-1");
      return 0;
    }
    s.insert(p);
  }
  cout << a.size() << endl;
  for (auto i : a) printf("%lld ", i);
  puts("");
  return 0;
}
