#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int p, k;
  cin >> p >> k;
  vector<long long int> even(64, 0), odd(64, 0);
  int ind = 0;
  while (p) {
    even[ind++] = p % k;
    p /= k;
  }
  int deg = -1;
  for (int i = 0; i < int(int((even).size())); i++) {
    if (even[i] >= k) {
      even[i] -= k;
      even[i + 1]++;
    }
    if (i % 2 && even[i]) {
      odd[i] = k - even[i];
      even[i] = 0;
      even[i + 1]++;
    }
    if (even[i] || odd[i]) deg = i + 1;
  }
  cout << deg << '\n' << even[0];
  for (int i = (int)(1); i < (int)(deg); i++) {
    cout << " " << odd[i] + even[i];
  }
  cout << '\n';
  return 0;
}
