输入只有一行,包含三个整数a,n,b。a表示其后的n 是a进制整数,b表示欲将a进制整数n转换成b进制整数。a,b是十进制整数,2 =< a,b <= 16。 数据可能存在包含前导零的情况。
可能有多组测试数据,对于每组数据,输出包含一行,该行有一个整数为转换后的b进制数。输出时字母符号全部用大写表示,即(0,1,...,9,A,B,...,F)。
15 Aab3 7
210306
while True:
try:
baseChar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numInput = input().split()
a = int(numInput[0])
b = int(numInput[2])
base10 = 0
temp = numInput[1].upper()
index = 0
while temp: #先转成10进制
base10 += baseChar.index(temp[-1])*a**index
index += 1
temp = temp[:-1]
result = []
while base10 > 0: #再转成b进制
base10, index = divmod(base10, b)
result.append(baseChar[index])
print("".join(result[::-1]))
except Exception:
break