#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
  char ch;
  bool flag = 0;
  for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1);
       ch = getchar())
    ;
  for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())
    ;
  x *= 1 - 2 * flag;
}
void print(long long x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
void write(long long x) {
  if (x < 0) putchar('-');
  print(((x) < 0 ? (-(x)) : (x)));
}
long long p, k, a[10005], d;
void work() {
  read(p), read(k);
  k = -k;
  while (p) {
    a[++d] = p % k, p /= k;
    if (a[d] < 0) a[d] = -k + a[d], p++;
  }
  (write(d), putchar('\n'));
  for (int i = 1; i <= d; i++) write(a[i]), putchar(' ');
}
int main() {
  work();
  return 0;
}
