#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long int n, m, k, q, x, y, f, val, t = 1, i, j;
long long int ind = -1, cnt, sz, sm, ans, mx = -1, mn = infl;
long long int a[1000004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("inp.txt", "r")) {
    freopen("myfile.txt", "w", stdout);
    freopen("inp.txt", "r", stdin);
  }
  cin >> x >> k;
  k *= -1;
  int sh = 0;
  vector<int> v;
  while (x != 0) {
    cnt++;
    val = (x % k);
    sh = 0;
    if (val < 0) {
      val -= k;
      sh = 1;
    }
    v.push_back(val);
    x /= k;
    x += sh;
  }
  cout << cnt << "\n";
  for (i = 0; i < v.size(); i++) cout << v[i] << " ";
  return 0;
}
