#include <bits/stdc++.h>
using namespace std;
long long Array[1000001];
signed main(void) {
  register long long i;
  register long long N, K;
  cin >> N >> K;
  register long long Ans = 0;
  while (N) {
    Ans++;
    N -= Array[Ans] = (N % K + K) % K;
    N /= K, N *= -1;
  }
  cout << Ans << endl;
  for (i = 1; i <= Ans; i++) cout << Array[i] << ' ';
  cout << endl;
  return 0;
}
