#include <bits/stdc++.h>
using namespace std;
const long long M = 1E9 + 7;
const long long NMAX = 211111;
const long long inf = 1E9;
const long double eps = 1e-2;
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  long long p, k;
  cin >> p >> k;
  long long x = -k;
  vector<long long> ans;
  while (p != 0) {
    if (p > 0) {
      long long y = p / abs(x);
      y = -y;
      ans.push_back(p - y * x);
      p = y;
    } else {
      long long y = (abs(p) + abs(x) - 1) / abs(x);
      ans.push_back(p - y * x);
      p = y;
    }
  }
  cout << ans.size() << endl;
  for (long long e : ans) cout << e << ' ';
  return 0;
};
