#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  vector<long long> t;
  while (n) {
    t.push_back(n % k);
    n /= k;
  }
  vector<long long> ans;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] >= k) {
      if (i + 1 == t.size()) {
        t.push_back(0);
      }
      t[i + 1] += t[i] / k;
      t[i] %= k;
    }
    if (i % 2 == 0) {
      ans.push_back(t[i]);
    } else {
      if (t[i] == 0) {
        ans.push_back(0);
        continue;
      }
      ans.push_back(k - t[i]);
      if (i + 1 == t.size()) t.push_back(0);
      t[i + 1]++;
    }
  }
  cout << ans.size() << "\n";
  for (int first : ans) cout << first << ' ';
}
