#include <iostream> #include <string> #include <cmath> using namespace std; int main() { int a, b; string str, res; long temp; int count; int t; while (cin >> a >> str >> b) { temp = 0; count = 0; for (int i = str.size() - 1; i >= 0; i--) { if (str[i] >= 'A' && str[i] <= 'Z') { t = str[i] - 'A' + 10; } else if (str[i] >= 'a' && str[i] <= 'z') { t = str[i] - 'a' + 10; } else { t = str[i] - '0'; } temp += t * pow(a, count); count++; } count = 0; int i = 0; while (temp) { t = temp % b; temp /= b; if (t > 9) { switch (t) { case 10: res.push_back('A'); break; case 11: res.push_back('B'); break; case 12: res.push_back('C'); break; case 13: res.push_back('D'); break; case 14: res.push_back('E'); break; case 15: res.push_back('F'); break; } } else { res.push_back(t + '0'); } } for (int j = res.size() - 1; j >= 0; j--) { cout << res[j]; } } } // 64 位输出请用 printf("%lld")