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
Linear Diophantine Equations
A linear Diophantine equation ax + by = c has integer solutions if and only if gcd(a, b) divides c.
#linear diophantine#extended euclidean algorithm#gcd+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
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