Permutations & Combinations
P(n, r) = \frac{n!}{(n - r)!}, \quad \binom{n}{r} = \frac{n!}{r!(n - r)!}
Permutations count ordered arrangements; combinations ignore order.
Counting principles, permutations and combinations, binomial coefficients, Euclidean GCD, and modular inverses used in CS theory and cryptography.
P(n, r) = \frac{n!}{(n - r)!}, \quad \binom{n}{r} = \frac{n!}{r!(n - r)!}
Permutations count ordered arrangements; combinations ignore order.
(a + b)^n = \sum_{k=0}^{n} \binom{n}{k} a^{n-k} b^k
Coefficients match row n of Pascals triangle.
ax + by = \gcd(a, b), \quad a \cdot a^{-1} \equiv 1 \pmod m
Modular inverse exists if and only if gcd(a, m) = 1.
a^{p-1} \equiv 1 \pmod p \quad (\text{prime } p \nmid a)
Used for fast modular exponentiation and RSA key computation.
The inverse of a modulo m exists if and only if a and m are coprime, meaning gcd(a, m) = 1. You compute it with the Extended Euclidean Algorithm.
Use permutations P(n, r) when sequence order matters (like rankings or passwords), and combinations C(n, r) when selecting an unordered subset (like committees).
Use binary exponentiation (repeated squaring), reducing modulo m after every multiplication so intermediate values stay smaller than m^2.