FunctionRacerProblemsRace

Power Mod

MediumMathPython, JavaScript, TypeScript

Return (base ** exp) % mod. The exponent can be huge, so do not compute the full power. Square the base and halve the exponent repeatedly instead. Do not use the three argument form of pow.

Example 1

base 2
exp 10
mod 1000
returns 24

1024 % 1000 = 24.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems