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
Lucas' Theorem
Lucas' Theorem lets you compute C(n, k) modulo a prime p by working digit-by-digit in base p.
#lucas theorem#binomial coefficient modulo p#prime power modulus+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
Chinese Remainder Theorem
The Chinese Remainder Theorem (CRT) reconstructs an integer from its remainders modulo pairwise coprime moduli and guarantees a unique answer modulo the product.
#chinese remainder theorem#crt#modular arithmetic+12
βMathIntermediate
Extended Euclidean Algorithm
The Extended Euclidean Algorithm finds integers x and y such that ax + by = gcd(a, b) while also computing gcd(a, b).
#extended euclidean algorithm#bezout coefficients#gcd+12