#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
}
int a[1000000], tot = -1;
int main() {
  long long p, k;
  tot = -1;
  read(p);
  read(k);
  while (p) {
    a[++tot] = p % k;
    p /= k;
  }
  for (int i = 0; i <= tot; i++) {
    if ((i & 1) && a[i]) a[i] = k - a[i], a[i + 1]++;
    if (a[i] >= k) a[i] -= k, a[i + 1]++;
  }
  for (tot = tot + 1; 1; ++tot) {
    if (a[tot] == 0) break;
    if (tot & 1) a[tot] = k - a[tot], a[tot + 1]++;
    if (a[tot] >= k) a[tot] -= k, a[tot + 1]++;
  }
  cout << tot << "\n";
  for (int i = 0; i < tot; i++) cout << a[i] << " ";
  return 0;
}
