class Solution {
public:
    string solve(int M, int N) {
        string ans;
        string zm = "0123456789ABCDEF";
        stack<char> st;
        int flag = false;
        if(M < 0) {M = -M; flag = true;}
        while(M){
            st.push(zm[M%N]);
            M = M/N;
        }
        if(flag) st.push('-');
        while(!st.empty()){
            ans += st.top();
            st.pop();
        }
        return ans;
    }
};