Super Pow

Given an integer a and an array of digits b representing a very large exponent, compute a^b mod 1337. The exponent is too large for normal integer storage, so the solution must use repeated modular reduction.

Input Format

a = base, b = exponent digits

Output Format

a^b mod 1337

Constraints

  • 1 <= a <= 2^31 - 1; 1 <= b.length <= 2000; 0 <= b[i] <= 9

Examples

Example 1:

Input:

a = 2
b = [3]

Output:

8

Explanation:

2^3 = 8.

Example 2:

Input:

a = 2
b = [1,0]

Output:

1024

Explanation:

2^10 = 1024.

Loading...
Super Pow - Math DSA Problem