#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
  long long p;
  int k;
  cin >> p >> k;
  int kol = 0;
  while (p > 0) {
    a[kol] = kol % 2 ? (k - p % k) % k : p % k;
    p = (kol % 2 ? (p + k - 1) : p) / k;
    kol++;
  }
  if (kol % 2 == 0) {
    a[kol++] = 1;
  }
  cout << kol << endl;
  for (int i = 0; i < kol; i++) cout << a[i] << " ";
  cout << endl;
  return 0;
}
