#include <bits/stdc++.h>
using namespace std;
long long p, k;
long long ans[1000010], a[1000010], tot;
inline void in(long long &x) {
  x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
}
int main() {
  in(p);
  in(k);
  a[0] = p / (-k);
  ans[0] = p % k;
  if (ans[0] < 0) ans[0] += k, a[0]++;
  for (int i = 1;; i++) {
    if (a[i - 1] == 0) break;
    tot++;
    a[i] = a[i - 1] / (-k);
    ans[i] = a[i - 1] % k;
    if (ans[i] < 0) ans[i] += k, a[i]++;
  }
  cout << tot + 1 << endl;
  for (int i = 0; i < tot; i++) cout << ans[i] << " ";
  cout << ans[tot];
}
