#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long p, k, cnt;
int f[1000];
int solve() {
  int x = p % k;
  if (x < 0) x += k;
  return x % k;
}
int main() {
  cin >> p >> k;
  while (p) {
    cnt++;
    f[cnt] = solve();
    p = p - solve();
    p = p / (-k);
  }
  printf("%d\n", cnt);
  for (int i = 1; i < cnt + 1; i++) cout << f[i] << " ";
}
