Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Example1:
a = 2
b = [3]
Result: 8
Example2:
a = 2
b = [1,0]
Result: 1024
class Solution(object):
def myPow(self, x, n,m):
ret=1
while n>0:
if n&1:ret*=x
x=(x*x)%m
n>>=1
return ret
def superPow(self, a, b):
"""
:type a: int
:type b: List[int]
:rtype: int
"""
ans,p=1,a
for i in b[::-1]:
ans=(ans*self.myPow(p,i,1337))%1337
p=self.myPow(p,10,1337)
return ans