Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Competitions › IOQM › unit 13 of 14

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?

In this lesson

  1. Why it works
  2. Complements
  3. Worked examples
  4. Where marks are lost
  5. Check yourself

1Why 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.

2Complements

“At least one” problems are easier as total minus “none”.

Worked examples

  1. Example 1How many numbers 1–1000 are divisible by none of 2, 3, 5?

    1. Divisible by at least one: 500 + 333 + 200 − 166 − 100 − 66 + 33 = 734.
    2. 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

  1. How many numbers from 1 to 100 are divisible by 2 or 5?

  2. How many from 1 to 30 are coprime to 30?

  3. 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.

  1. 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

  2. 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

  3. How many students play exactly one of the two sports?

    ξ = 51 studentsTennisKabaddi17121210
    Show the working

    Start: Leave out the overlap.

    17 + 12 = 29.

    Answer: 29

  4. 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.

  • SetsClass 11

Sit a timed IOQM mock test

CirclesNext: Pigeonhole principle and invariants