ShiShen_hu @ 2024-11-04 17:18:41
def add(n, m):
last = {"A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15}
n = [(int(i) if (i not in "ABCDEF") else last[i]) for i in str(n)]
n_ = n[::-1]
for i in range(len(n)-1, -1, -1):
x = n[i] + n_[i]
y = x % m
if y > 9:
n[i] = chr(65 + y - 10)
else:
n[i] = y
if x//m > 0:
if i == 0:
n.insert(0, x//m)
else:
n[i-1] += x//m
return "".join(map(str, n))
m = int(input())
n = input()
i = 1
while i <= 30:
n = add(n, m)
if n == n[::-1]:
print(f"STEP={i}")
break
i += 1
else:
print("Impossible!")