#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, l, sum = 0, flag = 0, m, a[2002], t, b[100];
int ans = 0, one[2002], two[2002], dp[2002][2002];
vector<string> vv;
using namespace std;
string toString(int n) {
  string str;
  stringstream ss;
  ss << n;
  ss >> str;
  return str;
}
string f(long long n, long long negBase) {
  if (n == 0) {
    vv.push_back("0");
    return "0";
  }
  string converted = "";
  while (n != 0) {
    int remainder = n % negBase;
    n /= negBase;
    if (remainder < 0) {
      remainder += (-negBase);
      n += 1;
    }
    converted = toString(remainder) + converted;
    vv.push_back(toString(remainder));
  }
  return converted;
}
int main() {
  long long p, k;
  cin >> p >> k;
  string s = f(p, -k);
  cout << vv.size() << '\n';
  for (auto i : vv) cout << i << " ";
}
