#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod = int(1e9) + 7;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
const int magic = 3;
void solve();
void init();
void dump(const vector<int>& a) {
  for (int i = 0; i < a.size(); i++) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  init();
  while (t--) {
    solve();
  }
  return 0;
}
void init(){};
const int MX = 100500;
int a[MX];
void solve() {
  long long p, k;
  cin >> p >> k;
  int l = 0;
  while (p) {
    while (p % k != 0) {
      p--;
      a[l]++;
    }
    l++;
    p /= -k;
  }
  cout << l << endl;
  for (int i = 0; i < l; i++) {
    cout << a[i] << ' ';
  }
  cout << endl;
}
