#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long p, k;
  cin >> p >> k;
  vector<long long> res;
  while (p != 0) {
    long long x = p % k;
    while (x < 0) x += k;
    res.emplace_back(x);
    p -= x;
    p /= k;
    p *= -1;
  }
  cout << res.size() << '\n';
  for (long long x : res) cout << x << ' ';
  cout << '\n';
}
