#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-12;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e3 + 4;
const int maxm = 1e3 + 4;
inline long long rule(long long x) { return (x %= MOD) += x < 0 ? MOD : 0; }
long long p, K;
vector<long long> v;
void dfs(long long p) {
  long double t = K - p;
  long long a = floor(t / K);
  if (a * K + p == K) a--;
  v.push_back(a);
  if (a == 0) return;
  dfs(a);
}
long long a[maxn];
int main() {
  int ik, i, j, k, kase;
  cin >> p >> K;
  dfs(p);
  cout << v.size() << endl;
  for (int i = 0; i < v.size() - 1; ++i) {
    a[i] += K * v[i];
    a[i + 1] += v[i];
  }
  a[0] += p;
  for (int i = 0; i < v.size(); ++i) cout << a[i] << ' ';
  return 0;
}
