This was another super easy one for me. That’s two super fast ones in a row. There’s more code in my solution just so it can be run from the command line than to solve the problem.
This problem was just checking to make sure you know that modular exponentiation is super fast on a computer. I learned that from doing another problem. So I just applied it here and that was that.
I seem to recall that I’ve tried working on this one before only to be completely unsuccessful. It feels pretty good to solve problems like that, especially given how quickly I solved it. Makes me feel smart and like I’m learning something during this Covid Winter.
modulo = 10**8
def solve(n, m):
if m == 1:
return n
return pow(n, solve(n, m - 1), 10**8)
if __name__ == '__main__':
import sys
n = eval(sys.argv[1])
m = eval(sys.argv[2])
print(solve(n, m))
import pytest
from problem import solve
_test_solve = (
(3, 2, 27),
(3, 3, 7625597484987 % (10**8)),
)
@pytest.mark.parametrize('n,m,expect', _test_solve)
def test_solve(n, m, expect):
assert expect == solve(n, m)