#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long p, k;
  cin >> p >> k;
  vector<long long> a(70, 0), deg(1, 1);
  for (int i = 1; i < 70; i++) {
    if (deg[i - 1] > p) {
      break;
    }
    deg.push_back(deg[i - 1] * k);
  }
  a[0] = p;
  for (int i = 0; i < 68; i++) {
    if (a[i] >= k) {
      a[i + 1] += (a[i] / k);
      a[i] %= k;
    }
    if ((i % 2 == 1) && (a[i] != 0)) {
      a[i + 1]++;
      a[i] = k - a[i];
    }
  }
  int mx;
  for (int i = 0; i < 70; i++) {
    if (a[i] != 0) mx = i;
  }
  cout << mx + 1 << endl;
  for (int i = 0; i <= mx; i++) {
    cout << a[i] << " ";
  }
}
