#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long mod1 = 998244353;
const long long mod = 1e9 + 7;
long long mod_mul(long long a, long long b) {
  a = a % mod;
  b = b % mod;
  return (((a * b) % mod) + mod) % mod;
}
long long inv(long long i) {
  if (i == 1) return 1;
  return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long pwr(long long a, long long b) {
  a %= mod;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long findMinNumber(long long n) {
  long long count = 0, ans = 1;
  while (n % 2 == 0) {
    count++;
    n /= 2;
  }
  if (count % 2) ans *= 2;
  for (int i = 3; i <= sqrt(n); i += 2) {
    count = 0;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    if (count % 2) ans *= i;
  }
  if (n > 2) ans *= n;
  return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b, cnt = 0, cnt1 = 0;
  cin >> a >> b;
  long long c = a;
  while (c >= b) {
    if (cnt % 2 == 1)
      c = (c + b - 1) / b;
    else
      c /= b;
    cnt++;
  }
  if (cnt % 2 == 1) cnt++;
  cout << cnt + 1 << '\n';
  while (a >= b) {
    if (cnt1 % 2 == 1) {
      cout << (b - a % b) % b << " ";
      a = (a + b - 1) / b;
    } else {
      cout << a % b << " ";
      a /= b;
    }
    cnt1++;
  }
  if (cnt1 % 2 == 1)
    cout << b - a << " ";
  else
    cout << a << " ";
  if (cnt1 % 2 == 1) cout << 1 << '\n';
  return 0;
}
