#include <bits/stdc++.h>
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")
using namespace std;
long long p;
int k, f;
vector<int> D;
int main() {
  cin >> p >> k;
  while (p) {
    if (f) {
      if (p % k) {
        D.push_back(k - p % k);
        p = p / k + 1;
      } else {
        D.push_back(0);
        p = p / k;
      }
    } else {
      D.push_back(p % k);
      p /= k;
    }
    f ^= 1;
  }
  printf("%u\n", D.size());
  for (int v : D) printf("%d ", v);
  return 0;
}
