๐ WAYPOINT LESSON
Combining Congruences
โญโญโญ advancedโณ 30 min read๐ Lesson 171 of 281
Euler's phi via a sieve, prefix sums for range answers, and CRT: x = a + n*t where t = (b - a) * n^(-1) (mod m).
Two clocks, one answer
phi(k) counts units mod k; the sieve subtracts phi[i]/p at each prime in one linear pass. CRT reuses the inverse: solving x = a (mod n), x = b (mod m) sets x = a + n*t and solves for t modulo m. Composite moduli need the general egcd inverse โ same idea, one more step.
โก Now practice
Ready to CodeNumber TrioModular inverses under load, factorial binomials at n = 1e6, and totient prefix sums.
3 challenges ยท ยท ~110 min