leetcode 372. Super Pow

Your task is to calculate a**b 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

1
2
3
4
5
6
7
8
9
10
11
class Solution(object):
def superPow(self, a, b):
"""
:type a: int
:type b: List[int]
:rtype: int
"""
#f(a,123456) = f(a,123450)*pow(a,6)=f(pow(a,10),12345)*pow(a,6)
#n1*n2%k = (n1%k)(n2%k)%k
if not b:return 1
return pow(a, b.pop(), 1337)*self.superPow(pow(a, 10, 1337), b)%1337