#include <bits/stdc++.h>
using namespace std;
long long n;
int k;
vector<int> a;
int main() {
  cin >> n >> k;
  while (n) {
    int t = (n % k + k) % k;
    n -= t;
    n /= k;
    n = -n;
    a.push_back(t);
  }
  printf("%d\n", (int)a.size());
  for (int i = 0; i < (int)a.size(); ++i) printf("%d ", a[i]);
  cout << endl;
}
