입력으로 2개의 숫자(or 숫자 + 문자)가 주어질 것이다.
첫번째 값은 10진수인 X를 A진법으로 표현한 값이며 두번째 값은 10진수인 X를 B진법으로 표현한 값이다.
이 때 X와 A, B를 차례대로 출력하는 문제이다.
결국 우리가 활용할 수 있는 최대값은 0 ~ 9 & a ~ z이다. 따라서 dict형식 Data에 처음부터 0 ~ 9, a ~ z와 대응되는 십진수값을 Value로 저장하기로 했다.
ASCII 코드 상으로 0 ~ 9는 a ~ z 앞 쪽에 존재하고, 진법의 경우도 마찬가지이다.
따라서, 주어진 2개의 값을 list형식으로 글자 단위로 쪼갠 이후 해당 글자의 Value + 1 값부터 진법으로 표현 가능한지를 확인하면 될 것이다.
예를 들어, a2b같은 경우 최대값은 b가 될 것이며, b는 11과 Match된다.
무조건 b를 활용해야하는 진법을 검사해야하므로 우리는 12진법부터 36진법까지 확인해보면 되는 것이다(z까지 활용했을 경우 36진법)
a,b=map(str,input().split())
numbers = dict()
count = 0
answer = [0, 0]
# 1부터 저장
for i in range(0, 10):
numbers[str(i)] = i
# a부터 저장
for i in range(26):
numbers[chr(97+i)] = i+10
a_max = max(list(a))
b_max = max(list(b))
def trans_notation(string, notation):
# string이 notation 진법일 때 10진법으로 바꾸는 명령어
temp = 0
for i in range(len(string)):
temp += ((int(notation)**i) * numbers[string[-1-i]])
return temp
for i in range(numbers[a_max]+1, 37):
for j in range(numbers[b_max]+1, 37):
if i == j:
# 문제 조건
continue
if trans_notation(a, i) == trans_notation(b, j):
# 문제 조건
if trans_notation(a, i) >= 2**63:
continue
answer[0] = i
answer[1] = j
count += 1
if count == 0:
print("Impossible")
elif count > 1:
print("Multiple")
elif count == 1:
print(trans_notation(a, answer[0]), answer[0], answer[1])