#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, N = 500;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long p, k, cur = 1;
  cin >> p >> k;
  int over[70]{};
  vector<long long> ans;
  for (int i = 0; i < 70; i++, p /= k) {
    if (!p and !over[i]) break;
    if (i % 2 == 0) {
      long long a = p % k + over[i];
      if (a >= k) over[i + 1] += a / k;
      ans.push_back(a % k);
    } else {
      long long a = p % k + over[i];
      over[i + 1] += a / k;
      ans.push_back(a % k == 0 ? 0 : k - a % k);
      if (a % k) over[i + 1]++;
    }
  }
  cout << ans.size() << '\n';
  for (long long i : ans) cout << i << ' ';
}
