#include <bits/stdc++.h>
using namespace std;
long long p;
int k;
vector<int> coe;
void dfs(long long cur) {
  if (0 <= cur && cur < k) {
    if (cur != 0) coe.push_back(cur);
    return;
  }
  int c = ((cur + k) % k + k) % k;
  coe.push_back(c);
  dfs((c - cur) / k);
}
void solve() {
  cin >> p >> k;
  coe.push_back(p % k);
  dfs(-p / k);
  printf("%d\n", (int)coe.size());
  for (auto c : coe) printf("%d ", c);
  puts("");
}
int main() {
  solve();
  return 0;
}
