#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
int a, b, c, d, n, m, k;
long long p;
long long solve(long long a, int k) {
  if (a < k && a >= 0) return 0;
  long long low = -a / k - 1;
  for (long long add = 0; add < 1000000000; ++add) {
    long long cur = a + k * (low + add);
    if (cur >= 0 && cur < k) return low + add;
  }
  return -1;
}
int main() {
  cin >> p >> k;
  vector<int> res;
  long long cur = p;
  for (int _n((1000000000) - 1), i(0); i <= _n; i++) {
    long long cand = solve(cur, k);
    if (!cand) break;
    res.push_back(cur + k * cand);
    cur = cand;
  }
  res.push_back(cur);
  printf("%d\n", (int)((res).size()));
  for (int _n(((int)((res).size())) - 1), i(0); i <= _n; i++) {
    if (i) printf(" ");
    printf("%d", res[i]);
  }
  printf("\n");
}
