#include <bits/stdc++.h>
using namespace std;
long long p;
int k, arr[2005], cur, xam;
bool flag;
int main() {
  scanf("%lld %d", &p, &k);
  while (p) {
    arr[cur] = p % k;
    cur++;
    p /= k;
  }
  flag = true;
  xam = cur;
  for (int i = 0; i < xam; i++) {
    if (i % 2 == 1 and arr[i] != 0) {
      xam = max(i + 2, cur);
      arr[i + 1]++;
      arr[i] = k - arr[i];
    } else if (i % 2 == 0) {
      if (arr[i] == k) {
        arr[i + 1]++;
        xam = max(i + 2, cur);
        arr[i] = 0;
      } else if (arr[i] > k) {
        flag = false;
      }
    }
  }
  if (!flag)
    printf("-1\n");
  else {
    printf("%d\n", xam);
    for (int i = 0; i < xam; i++) {
      printf("%d", arr[i]);
      if (i == xam - 1)
        printf("\n");
      else
        printf(" ");
    }
  }
}
