#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-7;
template <class T>
T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
vector<long long> ans;
int main() {
  long long p, k;
  scanf("%lld%lld", &p, &k);
  int sgn = 1;
  long long lft = p;
  while (lft >= k) {
    if (sgn == -1) {
      ans.push_back((lft + k - 1) / k * k - lft);
      lft = (lft + k - 1) / k;
    } else {
      ans.push_back(lft % k);
      lft = lft / k;
    }
    sgn *= -1;
  }
  if (sgn == -1) {
    ans.push_back(k - lft);
    ans.push_back(1);
  } else
    ans.push_back(lft);
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++)
    printf("%lld%c", ans[i], " \n"[i == (int)ans.size()]);
  return 0;
}
