#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 10;
long long a[maxn], b[maxn];
int main() {
  long long p = read(), k = read(), len = 1;
  b[0] = p;
  for (int i = 1; i < maxn; i++) {
    a[i] = (b[i - 1] % k + k) % k;
    b[i] = (a[i] - b[i - 1]) / k;
    len++;
    if (b[i] == 0) break;
  }
  cout << len - 1 << endl;
  for (int i = 1; i < len; i++) {
    cout << a[i] << ' ';
  }
  cout << endl;
  return 0;
}
