#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int BASE = 1000000007;
const int MAX = 2007;
const int MAXX = 1000000;
const int ADD = 1000000;
const int MOD = 1000000007;
const int CNT = 800;
bool U[8];
int main() {
  long long p, k;
  cin >> p >> k;
  vector<int> res;
  int t = 0;
  while (p) {
    if (t == 0) {
      res.push_back(p % k);
      p /= k;
    } else {
      res.push_back((k - p % k) % k);
      p = (p + k - 1) / k;
    }
    t ^= 1;
  }
  cout << (int)res.size() << endl;
  for (int i = (0); i < ((int)res.size()); i++) {
    cout << res[i] << ' ';
  }
  cout << endl;
  return 0;
}
