LeetCode 372, Medium. Topics: Math, Divide and Conquer. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:
Problem
Your task is to calculate a<sup>b</sup> mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Examples
Constraints
- 1 <= a <= 2^31 - 1
- 1 <= b.length <= 2000
- 0 <= b[i] <= 9
b does not contain leading zeros.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026