- i. GCD and Extended Euclid: with ; it runs in steps (worst case:
- ii. Linear Congruences and CRT: Everything here is extended Euclid (GCD and Extended Euclid) plus careful division.
- iii. Primes and Sieves: Sieving flips “for each , look at its divisors” into “for each , touch its multiples”:
- iv. Primality Testing and Factorization: using u64 = unsigned long long; using u128 = __uint128_t;
- v. Arithmetic Functions and Möbius: counts the integers in coprime to .
- vi. Harmonic Lemma and Floor Sums: takes at most distinct values as ranges over .
- vii. Sublinear Sieves and Prime Counting: Prefix sums of Euler’s phi and the Mobius function up to n ~ 1e10 in O(n^{2/3}) using Dirichlet convolution identities.
- viii. Factorials and Binomials mod p: Computing and — the case analysis depends entirely on how relates to .
- ix. Primitive Roots and Discrete Log: Group structure of (Z/nZ)*:
- x. Quadratic Residues and Modular Roots: is a quadratic residue modulo if has a solution.
- xi. Continued Fractions and Pell Equations: Continued fractions, convergents, closest fractions with bounded denominator and binary search over fractions.
- xii. Number Theory Miscellany: AP intersections, coprime bases, Pythagorean triples, counting roots of 1 and k-th powers, Fibonacci and Zeckendorf, power towers, balanced ternary, elliptic curves, Gaussian integers.