#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, K, b[N];
long long P, a[N];
long long cei(long long a, long long K) {
  if (a < 0)
    return -((-a) / K);
  else
    return (a + K - 1) / K;
}
int main() {
  cin >> P >> K;
  while (P) {
    b[++n] = P;
    P = cei(-P, K);
    b[n] += P * K;
  }
  cout << n << endl;
  for (int i = (1); i <= (n); i++) cout << b[i] << ' ';
  cout << endl;
  return 0;
}
