#include <iostream> #include <vector> using namespace std; //思路:现将M进制转成10进制,在从10进制转成N进制 //当进制数大于10时,涉及到字符和数字之间的转换 int charToInt(char c){ if(c >= '0' && c <= '9') return c - '0'; return c - 'A' + 10; } char intToChar(int a){ if(a >= 0 && a <= 9) return a + '0'; return a - 10 + 'A'; } int main() { int m, n; cin >> m >> n; string str; cin >> str; vector<char> res; long long number = 0; //转成10进制 for(int i = 0; i < str.length(); i ++){ number = number * m + charToInt(str[i]); } //转成n进制 while (number != 0) { res.push_back(intToChar(number % n)); number /= n; } for(int i = res.size() - 1; i >= 0; i --) cout << res[i]; return 0; }