#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const int Inf = 1000000007;
const long long mod = 998244353;
const double Pi = acos(-1);
void Fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long p, k, t, deg = 0;
long long a[1005];
void Solve() {
  cin >> k >> p;
  t = k;
  while (k > 0) {
    a[deg] = k % p;
    if (deg % 2 == 0) {
      k -= a[deg];
    } else {
      a[deg] = p - a[deg];
      if (a[deg] == p) {
        a[deg] = 0;
      }
      k += a[deg];
    }
    k /= p;
    deg++;
  }
  cout << deg << '\n';
  for (int i = 0; i < deg; i++) {
    cout << a[i] << " ";
  }
}
int main() {
  Fastio();
  Solve();
}
