Inclusion–exclusion and complements
IOQM · All sections · about 6 minutes
Counting with overlaps: add the sets, subtract the pairs, add back the triples. Often easier: count what you do not want and subtract.
Classic: how many numbers up to N are divisible by 2, 3 or 5?
Why it works
Adding |A| and |B| counts the overlap twice, so subtract it once. With three sets the middle region is added three times, subtracted three times, so add it back once.
Complements
“At least one” problems are easier as total minus “none”.
Worked examples
Example 1How many numbers 1–1000 are divisible by none of 2, 3, 5?
- Divisible by at least one: 500 + 333 + 200 − 166 − 100 − 66 + 33 = 734.
- 1000 − 734.
Answer: 266
Where marks are lost
- Forgetting to add back the triple intersection.
- Using a × b instead of lcm when they share factors.
Exam tips
- |A ∪ B| = |A| + |B| − |A ∩ B|.
- Three sets: + all singles − all pairs + the triple.
- Divisible by both a and b means divisible by lcm(a, b).
Practice questions
How many numbers from 1 to 100 are divisible by 2 or 5?
How many from 1 to 30 are coprime to 30?
In a class of 40, 25 like tea, 20 coffee, 10 both. How many like neither?
More worked examples
Try each one first, then open the working.
n(A) = 30, n(B) = 30, n(A ∩ B) = 3. n(A ∪ B)?
Show the working
Start: n(A) + n(B) − n(A ∩ B).
Add, then take away the overlap once.
Answer: 57
In a survey, 23 like tea, 15 coffee and 26 juice; 6 like tea and coffee, 8 coffee and juice, 7 tea and juice, and 4 like all three. How many like at least one?
Show the working
Start: Inclusion–exclusion for three sets.
n(A ∪ B ∪ C) = 23 + 15 + 26 − 6 − 8 − 7 + 4 = 47.
Answer: 47
How many students play exactly one of the two sports?
Show the working
Start: Leave out the overlap.
17 + 12 = 29.
Answer: 29
All the whole numbers from 0 to 511 are written in 9-bit binary. How many 1s are written in total?
Show the working
Start: Count position by position.
Each of the 9 positions is 1 in exactly half of the 512 numbers: 9 × 256 = 2304.
Answer: 2304
Practise more
New questions every time, at exam level
n(A) = 19, n(B) = 23, n(A ∩ B) = 2. n(A ∪ B)?
Learn it properly
Full chapters with animations, each with an “Explained simply” version.