#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, size_t N, class T>
void Fill(A (&a)[N], const T &v) {
  fill((T *)a, (T *)(a + N), v);
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int i = 0; i < (t.size()); i++) {
    os << t[i] << ",";
  }
  os << "}";
  return os;
}
template <class T, size_t n>
ostream &operator<<(ostream &os, const array<T, n> &t) {
  os << "{";
  for (int i = 0; i < (n); i++) {
    os << t[i] << ",";
  }
  os << "}";
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
const long long int INF = 1e9 + 7;
int main() {
  long long int p, k;
  cin >> p >> k;
  vector<long long int> ans;
  long long int m = p % k;
  ans.push_back(m);
  long long int c = (m - p) / k;
  while (c != 0) {
    long long int cn;
    if (c >= k) {
      cn = -c / k;
    } else if (c < 0) {
      cn = (-c - 1) / k + 1;
    } else {
      cn = 0;
    }
    ans.push_back(c + cn * k);
    c = cn;
  }
  cout << ans.size() << endl;
  for (auto t : ans) cout << t << " ";
  cout << endl;
  return 0;
}
