#mod:最后结果要取的模
def fast_pow(base, n, mod):
res = 1
if base == 0:
return 0
if n < 0:
base, n = 1 / base, -n
while n:
if n & 1:
res *= base % mod
base *= base
n >>= 1
return res
if __name__ == '__main__':
print(fast_pow(3, 4, 1000000))
标签:__,Python,res,fast,base,pow,快速,mod
From: https://blog.51cto.com/u_15944471/6077110