> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Super Pow Python Solution with Tests

> Tested Python solution for LeetCode 372 with 16 pytest cases. Generate a practice environment with lcpy.

LeetCode 372, [Medium](/catalog/medium). Topics: [Math](/catalog/topics/math), [Divide and Conquer](/catalog/topics/divide-and-conquer). [View on LeetCode](https://leetcode.com/problems/super-pow/description/).

Generate this problem as a practice environment: tested reference solution, 16 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 372   # by problem number
lcpy gen -s super_pow   # by problem name
```

## 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

```
Input: a = 2, b = [3]
Output: 8
```

```
Input: a = 2, b = [1,0]
Output: 1024
```

```
Input: a = 1, b = [4,3,3,8,5,2]
Output: 1
```

### 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](https://github.com/wislertt/leetcode-py/blob/main/leetcode/super_pow/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/super_pow/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n) where n = len(b)
    # Space: O(1)
    def super_pow(self, a: int, b: list[int]) -> int:
        mod = 1337
        result = 1
        a %= mod
        for digit in b:
            result = (pow(result, 10, mod) * pow(a, digit, mod)) % mod
        return result
```

## Complexity

| Time | Space |
| - | - |
| O(n) where n = len(b) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.