#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007, BIG = 0x3f3f3f3f;
long long p, k;
inline long long Mod(long long x, long long m) {
  x %= m;
  if (x < 0) x += m;
  return x;
}
vector<long long> Process() {
  vector<long long> ans;
  while (p) {
    const long long m = Mod(p, k);
    ans.push_back(m);
    p -= m;
    p /= -k;
  }
  return ans;
}
void Output() {
  const vector<long long> ans = Process();
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  while (cin >> p) {
    cin >> k;
    Output();
  }
  return 0;
}
