#include <iostream> #include <stack> #include <string> using namespace std; int main() { int M, N; cin >> M >> N; int flag = 0; if (M < 0) { M = -M; flag = -1; } if (M == 0) { cout << "0" << endl; return 0; } string str = "", str2 = ""; stack<int> s; while (M) { int t = M % N; s.push(t); M /= N; } string tmp = "0123456789ABCDEF"; while (!s.empty()) { int t = s.top(); str += tmp[t]; s.pop(); } if (flag) { str = "-" + str; } cout << str << endl; return 0; }