#include <bits/stdc++.h>
using namespace std;
long long int tc;
long long int suma, sumb;
long long int n, i, j, t, y, flag, mid, l, d, r, k, g, m, ans, x, h, z, sum,
    ctr, q, num, pos;
multiset<long long int> ms;
vector<long long int> a;
vector<long long int> b;
vector<pair<long long int, long long int>> f;
long long int c;
map<long long int, long long int> mp;
set<long long int> s;
set<long long int> ns;
map<long long int, vector<long long int>> mpn;
string st;
string ri;
map<pair<long long int, pair<long long int, long long int>>, long long int> ind;
priority_queue<long long int> pq;
int main() {
  const int N = 2e7 + 13;
  vector<int> mind(N, -1), val(N);
  mind[1] = 1;
  for (int i = 2; i < N; ++i)
    if (mind[i] == -1)
      for (int j = i; j < N; j += i)
        if (mind[j] == -1) mind[j] = i;
  for (int i = 2; i < N; ++i) {
    int j = i / mind[i];
    val[i] = val[j] + (mind[i] != mind[j]);
  }
  cin >> n >> k;
  x = n;
  num = 0;
  while (x) {
    a.push_back(x % k);
    x /= k;
    num++;
  }
  for (i = 0; i < 100; i++) {
    a.push_back(0);
  }
  t = 1;
  for (i = 0; i < num; i++) {
    if (a[i] == k && t == 1) {
      a[i] = 0;
      a[i + 1]++;
      num = max(num, i + 2);
    }
    if (t == -1 && a[i] != 0) {
      a[i] = k - a[i];
      a[i + 1]++;
      num = max(num, i + 2);
    }
    t *= -1;
  }
  cout << num;
  cout << endl;
  for (i = 0; i < num; i++) cout << a[i] << " ";
  a.clear();
  return 0;
}
