#include <bits/stdc++.h>
using namespace std;
long long p, k;
long long val[111], ans[111];
int main() {
  cin >> p >> k;
  val[0] = -(p / k);
  for (int pw = 0; pw < 100; ++pw) {
    if (val[pw] == 0) {
      for (int i = pw; i >= 0; --i) {
        ans[i + 1] = val[i] + val[i + 1] * k;
      }
      ans[0] = val[0] * k + p;
      cout << pw + 1 << endl;
      for (int i = 0; i < pw + 1; ++i) {
        cout << ans[i] << " ";
      }
      cout << endl;
      exit(0);
    }
    val[pw + 1] = -(val[pw] / k);
    if (val[pw + 1] * k + val[pw] < 0) ++val[pw + 1];
    if (val[pw + 1] * k + val[pw] >= k) --val[pw + 1];
  }
}
