#include <bits/stdc++.h>
using namespace std;
const long long inf = 2147483647;
long long read() {
  long long first = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    first = first * 10 + ch - '0';
    ch = getchar();
  }
  return first * f;
}
void print(long long first) {
  if (first < 0) putchar('-'), first = -first;
  short a[20] = {}, sz = 0;
  while (first > 0) a[sz++] = first % 10, first /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
long long n, m;
long long a[1111];
int nw;
int main() {
  n = read(), m = read();
  while (n) {
    nw++;
    a[nw] = n % m;
    n = n / m;
  }
  for (int i = 1; i <= nw; i++) {
    if (i % 2 == 0) a[i] = -a[i];
  }
  for (int i = 1; i <= nw + 10; i++) {
    if (a[i] < 0) {
      a[i + 1]++;
      a[i] += m;
    }
    if (a[i] >= m) a[i + 1]--, a[i] -= m;
  }
  while (a[nw + 1]) nw++;
  cout << nw << endl;
  for (int i = 1; i <= nw; i++) cout << a[i] << ' ';
  cout << endl;
}
