## Solution 1: Using Python's big integers ^{(accepted in 72 ms)}

Turn `b`

into a Python integer object (they grow arbitrarily large) and just use the `pow`

function (which supports a modulo paramenter).

```
def superPow(self, a, b):
return pow(a, int(''.join(map(str, b))), 1337)
```

## Solution 2: Using small ints

^{(accepted in 80 ms)}

Originally I went backwards (see solution 5) but then I saw other people go forwards and it's simpler. Sigh. Anyway... my version:

```
def superPow(self, a, b):
result = 1
for digit in b:
result = pow(result, 10, 1337) * pow(a, digit, 1337) % 1337
return result
```

Explanation: For example for a^{5347}, the above computes a^{5}, then a^{53}, then a^{534}, and then finally a^{5347}. And a step from one to the next can be done like a^{5347} = (a^{534})^{10} * a^{7}.

## Solution 3: Using recursion

^{(accepted in 92 ms)}

Obligatory recursive oneliner version of solution 2.

```
def superPow(self, a, b):
return pow(a, b.pop(), 1337) * pow(self.superPow(a, b), 10, 1337) % 1337 if b else 1
```

## Solution 4: Using `reduce`

^{(accepted in 80 ms)}

Obligatory `reduce`

-oneliner version of solution 2.

```
def superPow(self, a, b):
return reduce(lambda result, digit: pow(result, 10, 1337) * pow(a, digit, 1337) % 1337, b, 1)
```

## Solution 5: omg was i stupid

^{(accepted in 72 ms) My original do-it-yourself before I saw other people's solutions and wrote solutions 2-4. Using only small ints, also accepted in 72 ms: def superPow(self, a, b): result = 1 apower = a for digit in reversed(b): result = result * pow(apower, digit, 1337) % 1337 apower = pow(apower, 10, 1337) return result Explanation by example: a5347 = a5000 * a300 * a40 * a7 = (a1000)5 * (a100)3 * (a10)4 * a7 = (((a10)10)10)5 * ((a10)10)3 * (a10)4 * a7 Computing that from back to front is straightforward (or straightbackward?). }