Math and bits
Modular arithmetic, fast power, gcd and the sieve, then bit operations and subset masks.
About 4 hours of study
Learning objectives
- Compute modulo 10⁹ + 7 safely
- Use gcd, lcm and a sieve
- Use bit tricks and subset masks
Lessons
- 1
Math for contests
Modular arithmetic, fast power, gcd and lcm, and a sieve with vector<bool>: the number theory every contestant uses.
- 2
Bit tricks and subset masks Intermediate
Test, set and clear bits, use xor to cancel pairs, count one bits, and walk through every subset of a small set with a mask.
Module practice
- CP: The gcd of a listEasy
- CP: Count the primesMedium
- CP: n choose r, modulo a primeHard
- CP: Count the one bitsEasy
- CP: The lone numberMedium
- CP: Subsets with a given sumHard