#include <bits/stdc++.h>
using namespace std;
int arr[200006];
int ans[200006];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long int p, k;
  cin >> p >> k;
  int i = 0;
  while (p > 0) {
    arr[i] = p % k;
    p /= k;
    i++;
  }
  int carry = 0;
  int j = 0;
  while (j < i || carry != 0) {
    long long int coeff = arr[j] + carry;
    if (j & 1 && coeff > 0) {
      ans[j] = -(coeff - k) % k;
      carry = 1;
    } else {
      ans[j] = (coeff) % k;
      carry = coeff / k;
    }
    j++;
  }
  cout << j << endl;
  for (int i = 0; i < j; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
