#include <bits/stdc++.h>
using namespace std;
long long p, k, s[210354], ans;
int main() {
  cin >> p >> k;
  for (; p; p /= -k) p -= s[++ans] = (p % k + k) % k;
  cout << ans << endl;
  for (int i = 1; i <= ans; i++) printf("%lld ", s[i]);
}
