#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;
long long mem[4][1000001];
long long solve(int n, int cnt) {
  assert(cnt <= 3);
  if (mem[cnt][n] != -1) return mem[cnt][n];
  if (n == 0) {
    if (cnt == 3 || cnt == 0) return 1;
    return 0;
  }
  if (cnt == 3) {
    return mem[cnt][n] = (solve(n - 1, cnt) + solve(n - 1, 0)) % MOD;
  }
  if (cnt == 0) {
    return mem[cnt][n] = (solve(n - 1, 1) + solve(n - 1, 0)) % MOD;
  }
  return mem[cnt][n] = solve(n - 1, cnt + 1) % MOD;
}
int main() {
  long long p, k;
  cin >> p >> k;
  int pos = 1;
  int cur = p % k;
  vector<int> sol;
  int carry = 0;
  while (p || carry != 0) {
    cur = p % k + carry;
    if (pos) {
      if (cur == k) {
        carry = 1;
        sol.push_back(0);
      } else {
        carry = 0;
        sol.push_back(cur);
      }
    } else {
      if (cur == 0) {
        sol.push_back(0);
        carry = 0;
      } else {
        sol.push_back(k - cur);
        carry = 1;
      }
    }
    pos ^= 1;
    p /= k;
  }
  cout << sol.size() << endl;
  for (auto el : sol) cout << el << ' ';
}
