Super Pow - Problem
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.
For example, if a = 2 and b = [3], then b represents the number 3, so we need to calculate 2^3 mod 1337 = 8.
If a = 2 and b = [1,0], then b represents the number 10, so we need to calculate 2^10 mod 1337 = 1024.
Note: a and elements of b are guaranteed to be positive integers.
Input & Output
Example 1 — Basic Single Digit
$
Input:
a = 2, b = [3]
›
Output:
8
💡 Note:
b represents the number 3, so we calculate 2^3 mod 1337 = 8 mod 1337 = 8
Example 2 — Multi-digit Exponent
$
Input:
a = 2, b = [1,0]
›
Output:
1024
💡 Note:
b represents the number 10, so we calculate 2^10 mod 1337 = 1024 mod 1337 = 1024
Example 3 — Large Base with Modulo Effect
$
Input:
a = 2147483647, b = [2]
›
Output:
1198
💡 Note:
Large base: (2147483647^2) mod 1337. First reduce base: 2147483647 mod 1337 = 1198, then 1198^2 mod 1337 = 1198
Constraints
- 1 ≤ a ≤ 231 - 1
- 1 ≤ b.length ≤ 2000
- 0 ≤ b[i] ≤ 9
- b does not contain leading zeros except for the number 0 itself
Visualization
Tap to expand
Understanding the Visualization
1
Input
Base a=2, exponent b=[1,0] representing 10
2
Process
Use modular exponentiation to compute 2^10 mod 1337
3
Output
Result is 1024
Key Takeaway
🎯 Key Insight: Use modular exponentiation with digit-by-digit processing to handle arbitrarily large exponents efficiently
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code