import java.util.*;


public class Solution {
    /**
     * 进制转换
     * @param M int整型 给定整数
     * @param N int整型 转换到的进制
     * @return string字符串
     */
    public String solve (int M, int N) {
         // write code here
        if (M==0){
            return "0";
        }
        StringBuilder ret = new StringBuilder();
        String s = "0123456789ABCDEF";
        int i = 0;
        boolean f = false;
        if (M<0){
            f = true;
            M = -M;
        }

        while (M!=0){
            i = M%N;
            ret.append(s.charAt(i));//加入对应下标的值
            M/=N;
        }
        if (f){
            ret.append('-');
        }
        ret.reverse();//逆置


        return ret.toString();
    }
}