#include <iostream> #include <algorithm> using namespace std; const int MAXL = 1000; int n, k, ans[MAXL]; int main(void) { cin >> n >> k; if (!n) cout << 0 << endl; else { int m = 0; while (n) { ans[m++] = (n % (-k) + k) % k; n = (ans[m - 1] - n) / k; } for (int i = m - 1; i >= 0; i--) cout << char(ans[i] >= 10 ? ans[i] + 'A' - 10 : ans[i] + '0'); cout << endl; } return 0; }