#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e6 + 100;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long p, k;
  cin >> p >> k;
  vector<long long> A(MAXN, -1), a(MAXN);
  bool solved = false;
  for (int i = 0; i < MAXN; i++) {
    if (k == p) {
      a[i] = -1;
    } else if (k > p) {
      if ((k - p) % k == 0) {
        a[i] = (k - p) / k - 1;
      } else {
        a[i] = (k - p) / k;
      }
    } else {
      a[i] = (k - p) / k - 1;
    }
    A[i] = k * a[i] + p;
    p = a[i];
    if (A[i] < 0 or A[i] >= k) {
      break;
    }
    if (a[i] >= 0 and a[i] < k) {
      A[i + 1] = a[i];
      solved = true;
      break;
    }
  }
  if (solved) {
    vector<long long> res;
    for (int i = 0; i < MAXN; i++) {
      if (A[i] == -1) break;
      res.push_back(A[i]);
    }
    while (res.size() > 0 and res.back() == 0) res.pop_back();
    cout << res.size() << '\n';
    for (auto i : res) cout << i << ' ';
  } else {
    cout << -1;
  }
  return 0;
}
