Concepts5
βοΈAlgorithmIntermediate
Modular Arithmetic Pitfalls
Modular arithmetic is about working with remainders, but programming languages often return negative remainders, so always normalize with (a % MOD + MOD) % MOD.
#modular arithmetic#modular inverse#fermats little theorem+12
βMathIntermediate
Modular Arithmetic Basics
Modular arithmetic is arithmetic with wrap-around at a fixed modulus m, like numbers on a clock.
#modular arithmetic#mod#modulo c+++12
βMathIntermediate
Modular Inverse
A modular inverse of a modulo m is a number a_inv such that a Γ a_inv β‘ 1 (mod m).
#modular inverse#extended euclidean algorithm#fermats little theorem+12
βMathIntermediate
Euler's Theorem
Eulerβs Theorem says that if a and n are coprime, then a raised to the power Ο(n) is congruent to 1 modulo n.
#euler totient#euler theorem#modular exponentiation+12
βMathIntermediate
Fast Exponentiation
Fast exponentiation (binary exponentiation) computes a^n using repeated squaring in O(log n) multiplications.
#binary exponentiation#fast power#modular exponentiation+11