#include <bits/stdc++.h>
using namespace std;
inline int getidx(const vector<int>& ar, int x) {
  return lower_bound(ar.begin(), ar.end(), x) - ar.begin();
}
inline long long GCD(long long a, long long b) {
  long long n;
  if (a < b) swap(a, b);
  while (b != 0) {
    n = a % b;
    a = b;
    b = n;
  }
  return a;
}
inline long long LCM(long long a, long long b) {
  if (a == 0 || b == 0) return GCD(a, b);
  return a / GCD(a, b) * b;
}
inline long long CEIL(long long n, long long d) {
  return n / d + (long long)(n % d != 0);
}
inline long long ROUND(long long n, long long d) {
  return n / d + (long long)((n % d) * 2 >= d);
}
inline long long POW(long long a, long long n) {
  if (n < 0) return 0;
  long long ret = 1;
  while (n) {
    if (n % 2) ret *= a;
    a = a * a;
    n /= 2;
  }
  return ret;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
long long p, k;
vector<long long> a, b;
void input() { cin >> p >> k; }
int solve() {
  while (b.empty() || k <= b.back() || b.back() < 0) {
    if (b.empty())
      b.push_back(-p / k);
    else {
      if (b.back() < 0)
        b.push_back(CEIL(abs(b.back()), k));
      else
        b.push_back(-b.back() / k);
    }
  }
  a.push_back(k * b[0] + p);
  for (int(i) = (0); (i) < (int)(b.size() - 1); ++(i))
    a.push_back(b[i] + k * b[i + 1]);
  if (b.back() != 0) a.push_back(b.back());
  cout << a.size() << '\n';
  for (int(i) = (0); (i) < (int)(a.size()); ++(i)) cout << a[i] << ' ';
  cout << '\n';
  return 0;
}
void execute() { input(), solve(); }
int main(void) {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  execute();
  return 0;
}
