In a class of 60, 30 play cricket (C), 25 football (F) and 20 hockey (H); 10 play C and F, 8 play F and H, 7 play C and H, and 4 play all three. How many play (a) at least one game, (b) none, (c) exactly one, (d) exactly two, (e) cricket only?
Inclusion–exclusion counts a union by adding the set sizes, subtracting pairwise overlaps, adding triple overlaps and so on. With permutations, combinations, derangements and the pigeonhole principle it forms the counting toolkit on which classical probability is built.
The sum rule: if a task can be done in one of m ways or one of n other ways (no overlap), there are m + n ways. The product rule: if a task is a sequence of a step with m ways and a step with n ways, there are m × n ways. A password of two letters followed by three digits has 26² × 10³ = 676 000 possibilities.
| Situation | Formula | Example |
|---|---|---|
| Ordered selection of r from n, no repetition (permutation) | P(n, r) = n!/(n − r)! | P(10, 4) = 5 040 |
| Unordered selection of r from n (combination) | C(n, r) = n!/(r!(n − r)!) | C(10, 4) = 210 |
| Ordered, repetition allowed | nʳ | 4-digit PINs: 10⁴ = 10 000 |
| Unordered, repetition allowed (stars and bars) | C(n + r − 1, r) | x₁ + x₂ + x₃ = 10 with xᵢ ≥ 0: C(12, 2) = 66 |
| Arrangements of a multiset | n!/(n₁! n₂! … nₖ!) | BANANA: 6!/(3! 2! 1!) = 60 |
| Circular arrangements of n distinct objects | (n − 1)! | 6 people round a table: 5! = 120 |
Handy identities: C(n, r) = C(n, n − r); Pascal's rule C(n, r) = C(n − 1, r − 1) + C(n − 1, r); and C(n, 0) + C(n, 1) + … + C(n, n) = 2ⁿ. A committee of 3 men chosen from 6 and 2 women from 5 can be formed in C(6, 3) × C(5, 2) = 20 × 10 = 200 ways; conditions such as “at least two women” are handled by splitting into cases (sum rule) or by counting the complement.
Why the final plus sign? An element in all three sets is counted 3 times by the singles, removed 3 times by the pairs, and so must be added back once. In general an element that lies in exactly m of the sets is counted C(m, 1) − C(m, 2) + C(m, 3) − … = 1 time — that single identity is the whole proof of the principle.
| Quantity (three sets) | Formula |
|---|---|
| At least one | S₁ − S₂ + S₃ |
| None | |U| − (S₁ − S₂ + S₃) |
| Exactly one | S₁ − 2S₂ + 3S₃ |
| Exactly two | S₂ − 3S₃ |
| Exactly three | S₃ |
| A only | |A| − |A ∩ B| − |A ∩ C| + |A ∩ B ∩ C| |
Percentages hide the counts in a classic variant (2025 paper): 30 students take both mathematics and chemistry, which is 10% of the mathematics students and 12% of the chemistry students. Then |M| = 300, |C| = 250 and |M ∪ C| = 300 + 250 − 30 = 520.
The sieve form is the workhorse: to count objects with none of several “bad” properties, start from all N objects and correct for the bad ones. Euler's totient φ(n), the number of integers in 1…n coprime to n, falls straight out of it. For n = 60 = 2² · 3 · 5: φ(60) = 60 − (30 + 20 + 12) + (10 + 6 + 4) − 2 = 16, matching the product formula 60 × (1 − 1/2)(1 − 1/3)(1 − 1/5) = 16.
The number of multiples of d in {1, 2, …, N} is ⌊N/d⌋. An integer is divisible by both a and b exactly when it is divisible by lcm(a, b), which equals ab only when a and b are coprime.
The four-set version: integers 1…1000 divisible by none of 2, 3, 5, 7. S₁ = 500 + 333 + 200 + 142 = 1175; S₂ = 166 + 100 + 71 + 66 + 47 + 28 = 478; S₃ = 33 + 23 + 14 + 9 = 79; S₄ = ⌊1000/210⌋ = 4. Divisible by at least one: 1175 − 478 + 79 − 4 = 772, so 228 are divisible by none.
Digit questions usually go through the complement. Three-digit numbers (100–999) with at least one digit 3: there are 900 in all, and 8 × 9 × 9 = 648 contain no 3 (first digit from 1–9 except 3, the others from 0–9 except 3), so 900 − 648 = 252 contain a 3.
A derangement is a permutation in which no object stays in its original position. The classic stories: n letters put into n addressed envelopes with every letter in a wrong envelope; n guests collecting hats so that nobody gets their own; a Secret Santa draw in which nobody picks themselves.
Derivation by the sieve: let Aᵢ be the permutations that fix object i. Fixing k chosen objects leaves (n − k)! permutations, and there are C(n, k) ways to choose them, so Sₖ = C(n, k)(n − k)! = n!/k!. Hence Dₙ = n! − n!/1! + n!/2! − … .
Exactly r objects in the right place: choose them, then derange the rest — C(n, r) · Dₙ₋ᵣ. For 5 letters: all wrong 44; exactly one right 5 × D₄ = 45; exactly two right 10 × D₃ = 20; at least one right 120 − 44 = 76. Exactly four right is impossible (D₁ = 0): if four letters are correct, so is the fifth.
From an m-element set to an n-element set there are nᵐ functions. A function is onto (surjective) when every element of the codomain is hit. Applying the sieve to the property “element j is missed” gives the count of onto functions.
Interpretation: the number of ways to hand m distinct jobs to n distinct workers so that every worker gets at least one. Dividing by n! gives the Stirling number of the second kind S(m, n), the number of partitions of an m-set into n non-empty blocks (S(5, 3) = 150/6 = 25). If the objects are identical instead, use stars and bars: m identical sweets can be given to n children, each getting at least one, in C(m − 1, n − 1) ways.
Pigeonhole (Dirichlet's box) principle: if n + 1 or more objects are placed in n boxes, some box contains at least two objects. Generalised: if N objects are placed in k boxes, some box contains at least ⌈N/k⌉ objects. Equivalently, to guarantee r objects in one box you need k(r − 1) + 1 objects, and k(r − 1) are not enough.
| Situation | Boxes | Conclusion |
|---|---|---|
| 367 people (counting 29 February) | 366 possible birthdays | two share a birthday |
| 13 people | 12 months | two were born in the same month |
| Cards drawn from a deck to be sure of 3 of one suit | 4 suits | 4 × 2 + 1 = 9 cards |
| Students needed so that 6 surely get the same grade (A–E) | 5 grades | 5 × 5 + 1 = 26 |
| Any 5 numbers chosen from {1, …, 8} | pairs {1,8}, {2,7}, {3,6}, {4,5} | two of them add up to 9 |
| Any n + 1 integers | n remainders modulo n | two of them differ by a multiple of n |
The principle proves existence without saying which box, and its bounds are tight: with 8 cards you could hold exactly two of each suit, so 8 is not enough and 9 is the answer.
Try the problem first, then reveal the working one step at a time.
In a class of 60, 30 play cricket (C), 25 football (F) and 20 hockey (H); 10 play C and F, 8 play F and H, 7 play C and H, and 4 play all three. How many play (a) at least one game, (b) none, (c) exactly one, (d) exactly two, (e) cricket only?
Five letters are placed at random in five addressed envelopes, one per envelope. Find the number of ways in which (a) every letter is in a wrong envelope, (b) exactly one is correct, (c) at least one is correct, and (d) the probability that all are wrong.
Five different jobs are assigned to three different servers. In how many ways can this be done if every server must receive at least one job?
A drawer holds 10 black, 8 white and 6 grey socks. Taking socks without looking, how many must you take to be sure of (a) a matching pair, (b) two black socks?
How many integers from 1 to 1000 are divisible by 3, 5 or 7?
How many integers from 1 to 500 are divisible by none of 2, 3 and 5?
Four students exchange answer papers for peer evaluation. In how many ways can the papers be redistributed so that (a) nobody gets their own paper, (b) exactly one student gets their own paper?
How many people must be in a room to guarantee that at least 3 of them were born in the same month?
How many functions are there from a 4-element set to a 3-element set, and how many of them are onto?
10 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.