#include <bits/stdc++.h>
using namespace std;
int q[100100];
int d2b(long long n, long long b, int c[]) {
  int i = 0, k;
  while (n != 0) {
    k = n % b;
    n /= b;
    if (k < 0) {
      k -= b;
      n += 1;
    }
    c[i] = k;
    i++;
  }
  return i - 1;
}
long long p, k;
int main() {
  cin >> p >> k;
  int cnt = d2b(p, -k, q);
  cout << cnt + 1 << endl;
  for (int i = 0; i <= cnt; i++) cout << q[i] << " ";
  return 0;
}
