Concepts19
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.
Overflow Prevention Techniques
Integer overflow happens when a computed value exceeds the range of its type; in C++ this silently wraps for unsigned and is undefined for signed, so prevention is crucial.
Partition Function
The partition function p(n) counts the number of ways to write n as a sum of positive integers where order does not matter.
Stirling Numbers of First Kind
Stirling numbers of the first kind count permutations by their number of cycles and connect power polynomials to rising/falling factorials.
Stirling Numbers of Second Kind
Stirling numbers of the second kind S(n,k) count how many ways to split n labeled items into k non-empty, unlabeled groups.
Derangements
A derangement is a permutation with no element left in its original position, often written as !n or D(n).
Inclusion-Exclusion Principle
The Inclusion-Exclusion Principle (IEP) corrects overcounting by alternately adding and subtracting sizes of intersections of sets.
Stars and Bars
Stars and Bars counts the ways to distribute n identical items into k distinct bins using combinations.
Pollard's Rho Factorization
Pollard's Rho is a randomized algorithm that finds a non-trivial factor of a composite integer by walking a pseudorandom sequence modulo n and extracting a factor with a gcd.
Modular Arithmetic Basics
Modular arithmetic is arithmetic with wrap-around at a fixed modulus m, like numbers on a clock.
Modular Inverse
A modular inverse of a modulo m is a number a_inv such that a × a_inv ≡ 1 (mod m).
Fermat's Little Theorem
Fermat's Little Theorem says that for a prime p and integer a not divisible by p, a^{p-1} ≡ 1 (mod p).