Modular Inverse via Fermat
Divide under a modulus safely.
Division Breaks Under Mod
Add, subtract, and multiply behave nicely under a modulus, but plain division does not. You cannot just divide and take the remainder. ⚠️
Replace Divide with Multiply
The fix is the modular inverse: dividing by x becomes multiplying by the inverse of x. So a / b mod m turns into a times b's inverse.
All lessons in this course
- Work Modulo a Prime
- Fast Modular Exponentiation
- Modular Inverse via Fermat
- nCr with Precomputed Factorials