Skip to content

Commit 00c64d0

Browse files
authored
Create 0372 Super Pow.md
1 parent 0476d33 commit 00c64d0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

math/0372 Super Pow.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 372. Super Pow
2+
https://leetcode-cn.com/problems/super-pow/
3+
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.
4+
5+
Example 1:
6+
Input: a = 2, b = [3]
7+
Output: 8
8+
9+
Example 2:
10+
Input: a = 2, b = [1,0]
11+
Output: 1024
12+
13+
Example 3:
14+
Input: a = 1, b = [4,3,3,8,5,2]
15+
Output: 1
16+
17+
Constraints:
18+
1 <= a <= 2^31 - 1
19+
1 <= b.length <= 2000
20+
0 <= b[i] <= 9
21+
b does not contain leading zeros.
22+
23+
``` python3
24+
class Solution:
25+
def superPow(self, a: int, b: List[int]) -> int:
26+
base = 1337
27+
ans = 1
28+
for e in b:
29+
ans = pow(ans, 10, base) * pow(a, e, base) % base
30+
return ans
31+
```

0 commit comments

Comments
 (0)