#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
int s[N];
signed main() {
  ios::sync_with_stdio(false);
  long long p, k;
  cin >> p >> k;
  int cnt = 0;
  while (p) {
    long long x = p / -k;
    if (-k * x > p) x++;
    s[++cnt] = (p - (-k) * x);
    p = x;
  }
  cout << cnt << "\n";
  for (int i = 1; i <= cnt; i++) cout << s[i] << " ";
  cout << "\n";
}
