【題解】ZeroJudge d636: 大爆炸bomb

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=d636

def func(a, b):
    if b == 1:
        return a
    if b == 2:
        return a2
    if b % 2 == 0:
        return (func(a, b//2)**2) % 10007
    if b % 2 != 0:
        return (func(a, b//2)**2 * a) % 10007
    
while True:
    try:
        a, b = map(int, input().split())
        num = 1
        a = a % 10007
        a2 = a**2 % 10007
        print(func(a, b))
    except:
        break
分享本文 Share with friends