#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 1e5 + 7, maxd = 1e6 + 7;
const int mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;
long long p, k;
vector<long long> ans;
int main() {
  scanf("%lld %lld", &p, &k);
  long long t = p;
  while (1) {
    if (t > 0 && t < k) {
      ans.push_back(t);
      break;
    } else if (t == 0) {
      break;
    } else if (t >= k) {
      ans.push_back(t % k);
      t /= k;
      t *= -1;
    } else {
      if (t % k != 0) {
        ans.push_back((t % k) + k);
        t /= k;
        t *= -1;
        ++t;
      } else {
        ans.push_back(0);
        t /= k;
        t *= -1;
      }
    }
  }
  printf("%d\n", ans.size());
  for (auto i : ans) {
    printf("%lld ", i);
  }
  return 0;
}
