Inclusion–Exclusion
.
In plain terms. Add each group, subtract the double-counted overlaps, then add back what you subtracted too many times.
Example. Integers – divisible by or : .
Why it works. Follow one element that lies in exactly of the sets (). It is added times by the singles, subtracted times by the pairs, and added back times by the triple, for a net count of whether is , or . So every element of the union is counted exactly once. The alternating signs are not a patch: they are what makes each element's net contribution .
How many integers from to are divisible by none of , and ?
Spotting it. "None of" is the complement of "at least one of", and "at least one of" is a union: inclusion–exclusion, then subtract from the total.
Step 1. Singles: .
Step 2. Pairs (multiples of , , ): . Triple (multiples of ): .
Step 3. The union has elements, so integers are divisible by none.
Check with the density: a fraction of each block of survives, and ✓
In a club of students, play soccer, play basketball and play tennis. Nine play both soccer and basketball, both soccer and tennis, and both basketball and tennis; play none of the three. How many play all three?
Spotting it. Every number in the formula is given except the triple overlap, so inclusion–exclusion is one linear equation.
Step 1. students play at least one sport, so .
Step 2. .
Check by filling the Venn diagram from the centre out: soccer-and-basketball-only is , soccer-and-tennis-only , basketball-and-tennis-only ; soccer-only is , basketball-only , tennis-only . The seven regions add to ✓
How many -letter strings made from the letters A, B, C use all three letters?
Spotting it. "Uses all three" is hard to count directly (the repeated letters could be anywhere). Its complement, "misses at least one letter", is a union of three simple sets.
Step 1. All strings: . Missing a given letter: , three ways. Missing two given letters: string, three ways. Missing all three: impossible.
Step 2. Strings missing at least one letter: .
Step 3. So strings use all three. This is the count of onto functions from positions to letters, and the same pattern handles any "every box gets something" question.
Stopping after the pairs. For the integers to divisible by , or , the count is three short: the multiples of () were added three times and then subtracted three times, so they vanished. Adding back the triple overlap gives the correct .
How many integers from to are divisible by neither nor ?
Show the answerHide the answer
Multiples of : . Multiples of : . Multiples of both are the multiples of , not of : there are . So are divisible by at least one, and by neither. (Using for the overlap gives the wrong answer .)
Stars and Bars
Nonnegative solutions of number ; positive solutions number .
In plain terms. Line up identical items and dividers; where the dividers go decides who gets what. Counting the arrangements is one binomial.
Example. Give candies to kids: ways; if each must get one, .
Why it works. A distribution of identical items to people is the same thing as a row of stars and bars: the stars before the first bar go to person , those between the first two bars to person , and so on. Every row gives one distribution and every distribution gives one row, so count rows: choose which of the positions hold bars. For positive amounts, hand out one each first and distribute the remaining .
How many solutions in nonnegative integers does have with and ?
Spotting it. Lower bounds are handled by paying them up front, which turns the problem back into a plain stars-and-bars count.
Step 1. Put and . Then with all four nonnegative.
Step 2. stars and bars: .
How many solutions in nonnegative integers does have with every ?
Spotting it. Stars and bars cannot enforce a CAP directly, but it can count the violators: a variable that is at least is a lower bound, handled by paying up front. Then inclusion–exclusion removes them.
Step 1. Without caps: .
Step 2. Solutions with : put , so , giving . The same for and .
Step 3. Two variables cannot both be or more, since , so there are no pair corrections. The answer is .
Shifting by the wrong amount. " fails" means , so the shift is , not . Subtracting (from a shift of ) leaves instead of , and that absurd answer is the tell. Also keep the two formulas straight: for nonnegative parts, for positive ones.
In how many ways (order matters) can three standard dice show a total of ?
Show the answerHide the answer
Let , so with . Without the cap: . A violator has some ; shifting by leaves a sum of , which has solutions, and there are choices of . So .
Distributions, Arrangements and Overcounting
Ordered with repetition: . Ordered without: . Unordered without: . Unordered WITH repetition (stars and bars): .
Almost every counting error is choosing the wrong row of that table. The test is two questions: does order matter, and may items repeat? "How many ways to give identical candies to children" is unordered with repetition, ; "how many -digit PINs" is ordered with repetition, .
for a word with repeated letters; divide by the arrangements of the identical items.
BANANA has arrangements. Circular arrangements divide by instead (rotations are the same seating), giving , and if reflections also count as the same — a necklace — divide by more. Every one of those divisions is the same idea: count everything, then divide by the size of the group of motions you are calling identical.
How many ways can identical candies go to children if each child gets at least one?
Step 1 — give one to each first; remain.
Step 2 — distribute the freely: stars and bars with , gives . The "at least one" condition is always handled first, by pre-assigning the minimum and then counting freely.
In how many ways can people sit around a round table if Alice and Bob refuse to sit next to each other? (Rotations of a seating count as the same.)
Spotting it. "Not next to each other" is easiest as a complement: count all seatings, subtract those where they ARE together, and glue the pair into a block for the latter.
Step 1. All circular seatings of : .
Step 2. Alice and Bob together: treat them as one block, so units around the table give seatings, times for the order inside the block: .
Step 3. .
Forgetting that the groups are unlabelled. Splitting people into pairs is not : that counts each pairing once for every order in which its pairs could have been chosen. Divide by to get . Ask of every count: "if I relabel my choices, do I get a different outcome?" If not, divide.
How many arrangements of the letters of LEVEL are there?
Show the answerHide the answer
— two Ls and two Es.