Counting Strategies: Casework, Complementary & Overcounting

Study Sheet

Counting Strategies: Casework, Complementary & Overcounting

Competition counting & probability, Unit 2

Casework Counting

Concept
The idea

When a counting problem has no single clean formula, split it into cases that are mutually exclusive (no outcome lands in two cases) and exhaustive (every outcome lands in some case). Count each case separately, then add.

Total=(Case 1)+(Case 2)+⋯+(Case k).\text{Total} = (\text{Case 1}) + (\text{Case 2}) + \cdots + (\text{Case }k).

Choose your cases along the feature that is causing the trouble: the value of the largest digit, whether a coin came up heads, how many objects of a certain type were chosen, and so on. Good cases make each sub-count easy.

When no single formula applies, split into cases that do not overlap and cover everything, or count the complement ("at least one" is best counted as "all minus none"), or count with overcounting on purpose and divide by the repetition. Constructive counting — build the object one decision at a time — is the default strategy.

Example
Worked example: sums on two dice
123456123456first diesecondsum 3: 2sum 6: 5sum 9: 4sum 12: 1total 12
Each shaded anti-diagonal is one case (one sum); the cases never share a cell.

How many ordered pairs (a,b)(a,b) with a,b∈{1,…,6}a,b\in\{1,\dots,6\} have a+ba+b a multiple of 33?

Case a+b=3a+b=3: (1,2),(2,1)(1,2),(2,1) — 22 ways. Case a+b=6a+b=6: (1,5),(2,4),(3,3),(4,2),(5,1)(1,5),(2,4),(3,3),(4,2),(5,1) — 55 ways. Case a+b=9a+b=9: (3,6),(4,5),(5,4),(6,3)(3,6),(4,5),(5,4),(6,3) — 44 ways. Case a+b=12a+b=12: (6,6)(6,6) — 11 way. These cases are disjoint and cover all multiples of 33 between 22 and 1212, so the total is 2+5+4+1=122+5+4+1=\boxed{12}.

Side note
Where it goes wrong

Cases that overlap or leave a gap. Before adding case counts, state the criterion that assigns each outcome to exactly one case.

Example
Worked example: three-digit numbers with a fixed digit sum

How many three-digit numbers have digits summing to 55? Write the number as abc‾\overline{abc} with a≥1a\ge 1. Case on the hundreds digit aa: for each a∈{1,2,3,4,5}a\in\{1,2,3,4,5\} the tens and units must sum to 5−a5-a, giving (5−a)+1=6−a(5-a)+1=6-a ordered choices. Summing, 5+4+3+2+1=155+4+3+2+1=\boxed{15} numbers.

Tip

Pitfall: cases must not overlap. If an outcome could be counted in two cases, you will double count. Before adding, ask: “Could a single outcome satisfy two of my case descriptions?” If yes, redefine the cases (e.g. “exactly kk” instead of “at least kk”).

Try it
Quick check

How many two-digit numbers have digits that sum to 66?

Work it on paper before revealing the answer.

Show the answer

Answer: Two-digit numbers with digit sum 66. Write the number with tens digit tt and units digit uu, so we need t+u=6t+u=6. For a two-digit number the tens digit must satisfy 1≤t≤91\le t\le 9, while the units digit satisfies 0≤u≤90\le u\le 9. Once we pick tt, the units digit is forced to be u=6−tu=6-t, and this is a valid digit (00–99) exactly when 1≤t≤61\le t\le 6. Listing them:

16,  24,  33,  42,  51,  60.16,\; 24,\; 33,\; 42,\; 51,\; 60.

There are 6\boxed{6} such numbers.

Complementary Counting

Concept
The idea

Sometimes counting what you don't want is far easier than counting what you do. If there are NN total outcomes and BB “bad” outcomes, then the number of “good” outcomes is

Good=N−Bad.\text{Good} = N - \text{Bad}.

This shines when the good outcomes fracture into many messy cases but the bad ones form a tidy family (often a single case).

Example
Worked example: at least one repeated digit

How many three-digit numbers (100100 to 999999) have at least one repeated digit? Total three-digit numbers: 900900. The complement is “all digits distinct”: the hundreds digit has 99 choices (11–99), the tens digit 99 choices (any but the hundreds), the units 88 choices, giving 9⋅9⋅8=6489\cdot 9\cdot 8=648. Therefore the answer is 900−648=252900-648=\boxed{252}.

Side note
Where it goes wrong

Taking the wrong opposite. The opposite of "at least one repeated digit" is "no digit repeated", not "all digits the same". Subtracting the 99 numbers 111,222,…,999111, 222, \ldots, 999 gives 900−9=891900 - 9 = 891, which still includes every number like 121121 with exactly one repeat and many with none. Write the complement as a sentence with "no" or "none" in it before you count it: here, all three digits distinct, 648648 numbers, so 252252 have a repeat.

Tip

Tip: the complement trick pairs perfectly with the phrase “at least one.” The opposite of “at least one” is “none,” which is usually one clean product. See the final section.

Try it
Quick check

How many 44-letter strings of capital letters (AA–ZZ, repeats allowed) contain at least one vowel (A,E,I,O,UA, E, I, O, U)?

Work it on paper before revealing the answer.

Show the answer

Answer: Count the complement, strings with no vowel: each of the 44 positions is one of the 2121 consonants, 214=19448121^4 = 194481 strings. All strings: 264=45697626^4 = 456976. So

264−214=456976−194481=26249526^4 - 21^4 = 456976 - 194481 = 262495

strings contain a vowel. Counting "exactly one vowel, exactly two, …" directly would need four cases.   262495\boxed{262495}

Constructive Counting

Concept
The idea

Build a valid configuration one decision at a time, and multiply the number of choices at each step (the multiplication principle). The art is choosing an order of decisions so that the number of options at each step does not depend on the earlier choices in a way you cannot track. Make the most constrained decision first.

Example
Worked example: seating with a restriction
3endfill 1st3middlefill 3rd2middlefill 4th1middlefill 5th2endfill 2ndends: 3 × 2 = 6; middle: 3! = 6; total 36
Shaded end chairs are filled first, only by the three people who may sit there.

Five people sit in a row of five chairs, but Alice and Bob refuse to sit in the two end chairs. How many seatings are possible?

Solution. The end chairs are the bottleneck, so fill them first, from the 33 people who are neither Alice nor Bob: 33 choices for the left end, then 22 for the right end, 3⋅2=63\cdot 2 = 6 ways. The three middle chairs take the three people left (Alice, Bob and one other) in any order, 3!=63! = 6 ways. At every step the number of choices is the same whatever happened before, so the total is 6⋅6=366\cdot 6 = \boxed{36}.

Example
Worked example: strings with no two adjacent A's

How many length-44 strings over {A,B}\{A,B\} have no two adjacent AA's? Build left to right and case on the number of AA's. Equivalently, place the AA's in gaps around the BB's: with kk BB's there are k+1k+1 gaps and we choose positions for the AA's. For 0,1,20,1,2 A's we get (50)+(41)+(32)=1+4+3=8\binom{5}{0}+\binom{4}{1}+\binom{3}{2}=1+4+3=\boxed{8}.

Tip

Pitfall: the multiplication principle needs the count of options at each step to be constant, even if the specific options change. If step 3 sometimes offers 22 choices and sometimes 33 depending on step 1, split into cases first, then multiply within each case.

Try it
Quick check

How many odd four-digit numbers have four different digits?

Work it on paper before revealing the answer.

Show the answer

Answer: Most constrained first. Units digit: odd, 55 choices. Thousands digit: not 00 and not the units digit, 88 choices (the units digit is odd, so it is never 00, and the count is always 88). Hundreds digit: any of the 88 digits not yet used. Tens digit: 77. Total 5⋅8⋅8⋅7=22405\cdot 8\cdot 8\cdot 7 = \boxed{2240}.

Overcounting and Correcting

Concept
The idea

Often the easiest count treats some outcomes as different when they should be the same. If every final object is produced the same number of times dd by your over-count MM, then

Answer=Md.\text{Answer} = \frac{M}{d}.

The classic example: arranging nn distinct objects in a circle. Linear arrangements give n!n!, but each circular arrangement appears nn times (one per rotation), so the count is n!/n=(n−1)!n!/n=(n-1)!.

Example
Worked example: a necklace
ROYGB5 rotations× 2 flips= 10 rowsper necklace120 / 10 = 12
Turning the necklace or flipping it over the dashed axis changes the row you read, not the necklace.

How many distinct necklaces use 55 different colored beads if rotations and reflections are considered the same? Line them up: 5!=1205!=120 arrangements. Each necklace can be rotated 55 ways and flipped 22 ways, so it is counted 5⋅2=105\cdot 2=10 times. Answer: 120/10=12120/10=\boxed{12}.

Example
Worked example: choosing a committee counted twice

A club counts committees of 22 from 66 people by “pick a first member (66 ways), pick a second (55 ways)” getting 3030. But {X,Y}\{X,Y\} and {Y,X}\{Y,X\} are the same committee, counted d=2d=2 times. The true count is 30/2=15=(62)30/2=15=\binom{6}{2}, showing (nk)=n!/(n−k)!k!\binom{n}{k}=\dfrac{n!/(n-k)!}{k!} is exactly correcting for the k!k! orderings.

Side note
Where it goes wrong

Dividing when the overcount is not uniform. Bracelets of 44 beads, 22 black and 22 white, with rotations and flips identified: rows number 4!2! 2!=6\tfrac{4!}{2!\,2!} = 6, and a square has 88 symmetries, so "6/86/8" is not even a whole number. The two actual bracelets (blacks adjacent, blacks opposite) are produced 44 times and 22 times among the 66 rows, not 88 times each, because symmetric bracelets are fixed by some of the motions. Division needs every object counted equally often; otherwise use Burnside.

Tip

Pitfall: division only works when every object is overcounted the same number of times. If some beads repeat, or a symmetric arrangement is fixed by a rotation, the copies are not all distinct and simple division fails — you need Burnside-style counting (final section).

Try it
Quick check

How many diagonals does a convex decagon (1010 sides) have?

Work it on paper before revealing the answer.

Show the answer

Answer: Count from each vertex: a diagonal joins it to any vertex other than itself and its 22 neighbours, 10−3=710 - 3 = 7 diagonals per vertex, 10⋅7=7010\cdot 7 = 70 in all. Every diagonal was counted from both of its ends, exactly twice, so there are 70/2=3570/2 = \boxed{35}.

Bijections & Correspondences

Concept
The idea

To count a hard set AA, find a bijection (a one-to-one, onto pairing) with an easier set BB; then ∣A∣=∣B∣|A|=|B|. A bijection guarantees “no misses, no doubles.” Two famous correspondences:

  • Subsets ↔\leftrightarrow binary strings: subsets of an nn-set correspond to length-nn strings of 0/1, so there are 2n2^n subsets.
  • Stars and bars: the number of ways to write nn as an ordered sum of kk nonnegative integers equals (n+k−1k−1)\binom{n+k-1}{k-1}, by pairing each solution with an arrangement of nn stars and k−1k-1 bars.
Example
Worked example: stars and bars
x12x23x327 stars and 2 bars in 9 places
The row ⋆⋆∣⋆⋆⋆∣⋆⋆\star\star|\star\star\star|\star\star is the solution (2,3,2)(2,3,2); choosing the 22 bar places out of 99 fixes it.

How many solutions in nonnegative integers does x1+x2+x3=7x_1+x_2+x_3=7 have? Represent a solution as 77 stars split by 22 bars, e.g. ⋆⋆∣⋆⋆⋆∣⋆⋆\star\star|\star\star\star|\star\star. Each arrangement of 77 stars and 22 bars gives exactly one solution, so the count is (7+22)=(92)=36\binom{7+2}{2}=\binom{9}{2}=\boxed{36}.

Example
Worked example: lattice paths

How many shortest grid paths go from (0,0)(0,0) to (4,3)(4,3) moving only right/up? Each path is a sequence of 44 R's and 33 U's — a bijection with strings, so (73)=35\binom{7}{3}=\boxed{35}.

Tip

Tip: to prove your map is a bijection, describe the inverse: given an object in BB, recover exactly one object in AA. If you can undo the map uniquely, it is a bijection.

Try it
Quick check

In how many ways can 99 be written as an ordered sum of 33 positive integers (for example 2+5+22+5+2)?

Work it on paper before revealing the answer.

Show the answer

Answer: Line up 99 stars. An ordered sum of 33 positive parts is the same as cutting the row in 22 of the 88 gaps between neighbouring stars, one cut per gap (a gap can hold only one cut, or a part would be empty). The map is reversible: the part sizes tell you where the cuts are. So the count is (82)=28\binom82 = \boxed{28}.

“At Least One” via the Complement

Concept
The idea

The event “at least one” is the complement of “none.” In counting,

#(at least one X)=(total)−#(no X),\#(\text{at least one }X) = (\text{total}) - \#(\text{no }X),

and in probability, P(at least one)=1−P(none)P(\text{at least one})=1-P(\text{none}). Because “none” usually means every trial avoids XX independently, its count/probability is a single product.

Example
Worked example: at least one six

Roll a fair die 44 times. Probability of at least one six? “No six” on all four rolls has probability (56)4=6251296\left(\tfrac{5}{6}\right)^4=\tfrac{625}{1296}. So P(at least one six)=1−6251296=6711296P(\text{at least one six})=1-\tfrac{625}{1296}=\boxed{\tfrac{671}{1296}}.

Tip

Tip: watch for the words at least, at most, some, none. These almost always signal complementary counting. “At least one” →\to subtract “none”; “at most one” →\to subtract “two or more.”

Try it
Quick check

A coin is flipped 33 times. How many of the possible outcomes show at least one head?

Work it on paper before revealing the answer.

Show the answer

Answer: At least one head in 33 flips. Each flip has 22 outcomes, so there are 23=82^3=8 total sequences. Use complementary counting: the only outcome with no head is TTTTTT, which is 11 outcome. Therefore the number with at least one head is

8−1=7.8-1=\boxed{7}.

Going Deeper: Combining Strategies

Concept
Layering techniques

Contest problems rarely use one idea in isolation. Common combinations:

  • Casework ++ complementary: split off the easy-to-count bad outcomes with cases, subtract from the total. E.g. “at least two of a kind” == total −- (all distinct).
  • Constructive ++ overcounting: build with the multiplication principle, then divide out an ordering or symmetry you introduced (this is exactly how (nk)\binom{n}{k} arises).
  • Casework inside a bijection: map to an easier set, then do casework there.
Concept
Correcting for symmetry: a Burnside flavor

When simple division fails because some arrangements are fixed by a symmetry, use the Burnside idea: the number of distinct arrangements equals the average number of arrangements left unchanged by each symmetry:

#(distinct)=1∣G∣∑g∈GFix(g),\#(\text{distinct}) = \frac{1}{|G|}\sum_{g\in G}\text{Fix}(g),

where GG is the group of symmetries (e.g. the nn rotations of a circle) and Fix(g)\text{Fix}(g) counts colorings unchanged by gg. When no nontrivial symmetry fixes any coloring, every Fix(g)=0\text{Fix}(g)=0 except the identity, and Burnside collapses to the plain division M/∣G∣M/|G|.

Example
Worked example: Burnside on a bracelet

Color the 33 beads of a triangular bracelet with 22 colors, rotations only (GG has 33 elements: rotate by 0,1,20,1,2). Identity fixes all 23=82^3=8 colorings; each nontrivial rotation fixes only the 22 monochromatic colorings. By Burnside, 13(8+2+2)=123=4\tfrac{1}{3}(8+2+2)=\tfrac{12}{3}=\boxed{4} distinct bracelets.

Tip

Big picture: every strategy here answers the same question — “how do I count each valid outcome exactly once?” Casework partitions the outcomes; complementary counting flips to the easier side; constructive counting sequences the decisions; overcounting/Burnside repairs double counts; bijections transport the problem somewhere friendlier. When stuck, ask three questions: Is the opposite easier to count? Can I break this into clean cases? Am I counting anything more than once?

Try it
Quick check

How many two-digit numbers contain the digit 77 at least once?

Work it on paper before revealing the answer.

Show the answer

Answer: Two-digit numbers containing the digit 77. There are 9090 two-digit numbers in all (1010 through 9999). Count the complement — those with no 77. The tens digit must be one of {1,2,3,4,5,6,8,9}\{1,2,3,4,5,6,8,9\}: 88 choices. The units digit must be one of {0,1,2,3,4,5,6,8,9}\{0,1,2,3,4,5,6,8,9\}: 99 choices. So 8⋅9=728\cdot 9=72 numbers avoid the digit 77, and

90−72=1890-72=\boxed{18}

contain at least one 77.

Burnside's Lemma (Orbit-Counting Theorem)

Concept
The statement

Let a finite group GG of symmetries act on a set XX of configurations (colorings, labelings, …). Two configurations are “the same” when one can be carried to the other by some g∈Gg\in G; the resulting equivalence classes are called orbits. The number of distinct configurations is the number of orbits, and

#(orbits)  =  1∣G∣∑g∈G∣Fix(g)∣,\#(\text{orbits}) \;=\; \frac{1}{|G|}\sum_{g\in G}\bigl|\mathrm{Fix}(g)\bigr|,

where Fix(g)={x∈X:g⋅x=x}\mathrm{Fix}(g)=\{x\in X : g\cdot x = x\} is the set of configurations left unchanged by gg. In words: the number of distinct objects equals the average number of colorings fixed by a symmetry. This is the rigorous repair for the “divide by symmetry” shortcut, and it never overcounts even when some configurations have extra symmetry.

Concept
The workhorse formula for colorings

When gg permutes the nn “slots” (beads, faces, cells) and you may color each slot freely with cc colors, a coloring is fixed by gg iff every slot in a cycle of gg receives the same color. Hence

∣Fix(g)∣  =  c cyc(g),\bigl|\mathrm{Fix}(g)\bigr| \;=\; c^{\,\mathrm{cyc}(g)},

where cyc(g)\mathrm{cyc}(g) is the number of disjoint cycles of gg (fixed points count as 11-cycles). So the whole problem reduces to a cycle census of the group.

Example
Worked example: two-color bracelets of 66 beads
through 2 beads: 4 cyclesthrough 2 edges: 3 cycles3 axes, 16 fixed each3 axes, 8 fixed each
A flip through two opposite beads fixes those two and swaps two pairs; a flip through two opposite edges swaps three pairs.

Count the distinct bracelets of 66 beads, each black or white, where rotations and reflections are considered the same. The symmetry group is the dihedral group D6D_6 with ∣G∣=12|G|=12. Take a cycle census, using ∣Fix(g)∣=2cyc(g)\bigl|\mathrm{Fix}(g)\bigr|=2^{\mathrm{cyc}(g)}.

Rotations by kk positions have gcd⁡(k,6)\gcd(k,6) cycles:

k012345cyc6123212cyc6424842sum =84.\begin{array}{c|cccccc} k & 0 & 1 & 2 & 3 & 4 & 5\\\hline \mathrm{cyc} & 6 & 1 & 2 & 3 & 2 & 1\\ 2^{\mathrm{cyc}} & 64 & 2 & 4 & 8 & 4 & 2 \end{array} \qquad\text{sum }=84.

Reflections (six of them, since nn is even): 33 axes pass through two opposite beads (22 fixed beads +2+2 swaps =4=4 cycles ⇒24=16\Rightarrow 2^4=16 each), and 33 axes pass through opposite edges (33 swaps =3=3 cycles ⇒23=8\Rightarrow 2^3=8 each). Reflection sum =3(16)+3(8)=48+24=72=3(16)+3(8)=48+24=72. Therefore

#(bracelets)=84+7212=15612=13.\#(\text{bracelets}) = \frac{84+72}{12} = \frac{156}{12} = \boxed{13}.

(Rotations alone would give 84/6=1484/6=14 necklaces; folding in reflections identifies one mirror pair, leaving 1313.)

Example
Worked example: coloring the faces of a cube with 33 colors

How many distinct ways can the 66 faces of a cube be painted using 33 available colors, where two paintings are the same if a rotation of the cube carries one to the other? The rotation group has ∣G∣=24|G|=24. Census of how each rotation type permutes the 66 faces:

rotationhow manycyc(g)3cyc(g)identity1672990∘ or 270∘ about a face axis6327180∘ about a face axis3481120∘ or 240∘ about a vertex axis829180∘ about an edge axis6327\begin{array}{l|c|c|c} \text{rotation} & \text{how many} & \mathrm{cyc}(g) & 3^{\mathrm{cyc}(g)}\\\hline \text{identity} & 1 & 6 & 729\\ 90^\circ\text{ or }270^\circ\text{ about a face axis} & 6 & 3 & 27\\ 180^\circ\text{ about a face axis} & 3 & 4 & 81\\ 120^\circ\text{ or }240^\circ\text{ about a vertex axis} & 8 & 2 & 9\\ 180^\circ\text{ about an edge axis} & 6 & 3 & 27 \end{array}

Averaging over the group,

1⋅729+6⋅27+3⋅81+8⋅9+6⋅2724=729+162+243+72+16224=136824=57.\frac{1\cdot 729 + 6\cdot 27 + 3\cdot 81 + 8\cdot 9 + 6\cdot 27}{24} = \frac{729+162+243+72+162}{24} = \frac{1368}{24} = \boxed{57}.

The same recipe with cc colors gives 124(c6+3c4+12c3+8c2)\tfrac{1}{24}(c^6+3c^4+12c^3+8c^2) colorings.

Tip

Method: (1) identify the symmetry group GG and its size; (2) sort the elements into a few types (identity, rotations by angle, reflections through this-or-that axis); (3) for each type find cyc(g)\mathrm{cyc}(g) and multiply ccyc(g)c^{\mathrm{cyc}(g)} by how many elements have that type; (4) add and divide by ∣G∣|G|. The answer is always an integer — a fast sanity check on your census.

Try it
Quick check

How many necklaces of 44 beads can be made with 33 available colours, if two necklaces are the same when one is a rotation of the other (no flipping)?

Work it on paper before revealing the answer.

Show the answer

Answer: The group is the 44 rotations. Cycle census on the 44 bead positions: the identity has 44 cycles (34=813^4 = 81 fixed colourings); rotation by one or three places is a single 44-cycle (33 each); rotation by two places swaps opposite beads, 22 cycles (32=93^2 = 9). Burnside:

81+3+9+34=964=24.\frac{81 + 3 + 9 + 3}{4} = \frac{96}{4} = 24.

There are 24\boxed{24} necklaces.

The “Divide by Symmetry” Trap, Formalized

Concept
When plain division is legal

The shortcut Answer=M/∣G∣\text{Answer}=M/|G| (over-count divided by the number of symmetries) is valid exactly when the group action is free: no nontrivial symmetry fixes any configuration, so every orbit has the full size ∣G∣|G|. This is the regular/free case. Equivalently, by the orbit–stabilizer theorem,

∣orbit of x∣=∣G∣∣Stab(x)∣,|\text{orbit of }x| = \frac{|G|}{|\mathrm{Stab}(x)|},

so orbits all have size ∣G∣|G| precisely when every stabilizer is trivial. If some configuration is fixed by a nontrivial gg (a symmetric coloring), its orbit is smaller than ∣G∣|G|, plain division undercounts the collapse and gives the wrong answer, and you must use Burnside.

Example
Worked example: why 26/122^6/12 is wrong for bracelets

Naively “262^6 colorings, divide by 1212 symmetries” gives 64/12=5.33…64/12=5.33\dots — not even an integer, a red flag. The action is not free: the all-black bracelet is fixed by all 1212 symmetries (stabilizer size 1212, orbit size 11), and a bracelet like BWBWBW is fixed by several rotations and reflections. These small orbits are exactly what Burnside's averaging accounts for, producing the correct 1313 from the previous section. Plain division is only correct for the asymmetric colorings, whose orbits genuinely have full size 1212.

Example
Worked example: seating where division is legal

Seat 77 distinct people around a round table; rotations are equivalent (no reflections). No nontrivial rotation can fix an arrangement of 77 distinct people, so the action of the 77 rotations is free and every orbit has size 77. Plain division is valid: 7!7=6!=720\frac{7!}{7}=6!=\boxed{720}. The distinctness of the objects is what guarantees freeness.

Tip

Decision rule: before dividing by ∣G∣|G|, ask “could any nontrivial symmetry leave a configuration unchanged?” If the objects being arranged are all distinct and GG is just rotations, usually no — divide freely. If repeats are allowed (colorings) or reflections are included, symmetric configurations almost always exist — reach for Burnside. A non-integer after dividing is proof the action was not free.

Complementary Counting Meets Inclusion–Exclusion

Concept
Counting the complement of a union

The strongest complementary arguments subtract a union of bad events, and unions are handled by inclusion–exclusion:

∣ A1∪⋯∪An‾ ∣=N−∑i∣Ai∣+∑i<j∣Ai∩Aj∣−⋯+(−1)n ∣A1∩⋯∩An∣.\Bigl|\,\overline{A_1\cup\cdots\cup A_n}\,\Bigr| = N - \sum_i |A_i| + \sum_{i<j}|A_i\cap A_j| - \cdots + (-1)^n\,|A_1\cap\cdots\cap A_n|.

Use this when “good” means “avoids every one of several forbidden features.” The intersections are usually easy products, even when the individual good count is a casework nightmare.

Example
Worked example: integers coprime-ish to 2,3,52,3,5
mult. of 2mult. of 3mult. of 526713467133673333266U = 1000
The seven regions inside the circles hold 734734 numbers; the 266266 outside are divisible by none of 2,3,52, 3, 5.

How many integers in {1,2,…,1000}\{1,2,\dots,1000\} are divisible by none of 2,3,52,3,5? Let ApA_p be the multiples of pp. Then ∣A2∣=500, ∣A3∣=333, ∣A5∣=200|A_2|=500,\ |A_3|=333,\ |A_5|=200; pairwise ∣A6∣=166, ∣A10∣=100, ∣A15∣=66|A_6|=166,\ |A_{10}|=100,\ |A_{15}|=66; and ∣A30∣=33|A_{30}|=33. The count divisible by at least one is

500+333+200−166−100−66+33=734,500+333+200-166-100-66+33 = 734,

so the answer is the complement 1000−734=2661000-734=\boxed{266}.

Example
Worked example: surjections via inclusion–exclusion

How many functions from a 55-element set onto a 33-element set {1,2,3}\{1,2,3\} are there? Let AiA_i be the functions that miss value ii. A surjection avoids every AiA_i, so

#(onto)=∑k=03(−1)k(3k)(3−k)5=35−3⋅25+3⋅15=243−96+3=150.\#(\text{onto}) = \sum_{k=0}^{3}(-1)^k\binom{3}{k}(3-k)^5 = 3^5 - 3\cdot 2^5 + 3\cdot 1^5 = 243 - 96 + 3 = \boxed{150}.

Direct casework on the “shape” of the preimages (3+1+13{+}1{+}1 vs. 2+2+12{+}2{+}1) also works but is error-prone; the complementary/IE form is mechanical.

Tip

Tip: inclusion–exclusion signs alternate, so a sign slip is the most common mistake. Check the last term's sign: with nn forbidden properties it is (−1)n(-1)^n. Also verify a small case by hand (e.g. surjections from a 22-set onto a 22-set should give 22) before trusting the general formula.

Systematic Casework and Generating Functions

Concept
Choosing what to case on

Two cases are not equal in quality. Aim for a parameter that is most constraining and symmetry-friendly:

  • Case on the extreme: the largest element, the maximum multiplicity, the position of the first success. Extremes split the problem into independent “above” and “below” pieces.
  • Exploit symmetry to fuse cases: if the roles of two variables are interchangeable, count one ordering and multiply (remember to halve the tie case). This can cut the case count in half or more.
  • Prefer few fat cases over many thin ones: a parameter taking 33 values, each an easy product, beats one taking 1212 values you must enumerate.
Concept
Generating functions as bookkeeping

A generating function replaces casework with algebra: the number of ways to choose objects with a target total is a coefficient in a product of polynomials/series. Each factor encodes one independent choice; multiplying performs the “add over all splits” automatically. Bounded choices give finite polynomials; a single die is x+x2+⋯+x6=x(1−x6)1−xx+x^2+\cdots+x^6=\dfrac{x(1-x^6)}{1-x}.

Example
Worked example: three dice summing to 1010 — casework vs. GF

In how many ordered ways do three dice (11–66) sum to 1010? The generating function is (x+x2+⋯+x6)3\bigl(x+x^2+\cdots+x^6\bigr)^3, and we want the coefficient of x10x^{10}. Shift each die by 11 (let a′=a−1a'=a-1, etc.), so we need a′+b′+c′=7a'+b'+c'=7 with 0≤a′,b′,c′≤50\le a',b',c'\le 5. Unbounded stars and bars gives (92)=36\binom{9}{2}=36; subtract the solutions where some variable exceeds 55 (i.e. is ≥6\ge 6). Forcing one variable up by 66 leaves a sum of 11 among three nonnegative variables, (32)=3\binom{3}{2}=3 ways, and there are 33 choices of which variable overflowed (no two can overflow since 2⋅6>72\cdot 6>7). Thus

36−3⋅3=27.36 - 3\cdot 3 = \boxed{27}.

Compare the raw casework: summing #{a+b=10−c}\#\{a+b=10-c\} over c=1,…,6c=1,\dots,6 forces you to track the 11–66 bounds on a,ba,b case by case; the GF/IE route handles every bound in one subtraction.

Tip

Tip: the substitution “a′=a−(lower bound)a'=a-(\text{lower bound})” turns any ≥\ge constraint into a nonnegativity constraint so stars and bars applies; each upper bound violation is then removed by one inclusion–exclusion term (shift the offending variable past its ceiling). If at most one variable can overflow, that correction is a single clean subtraction, as above.

Why It Works

Casework is legitimate because the cases partition the set: every object is in exactly one, so the counts add. Complementary counting is ∣A∣=∣S∣−∣Ac∣|A| = |S| - |A^c|, the simplest instance of inclusion–exclusion. Dividing by symmetry works when each object is counted the same number of times — circular arrangements of nn people are n!n=(n−1)!\tfrac{n!}{n} = (n-1)! because each seating is counted once per rotation, and all nn rotations of a seating are the same arrangement.

Tip
Reading a proof

Do not read a proof the way you read a rule. Cover the last line, ask what the previous line forces, and only then uncover it. If a step feels like magic, that is the step to work by hand with a concrete number.

Formulas, Proofs & Tips

Tip
Complementary counting and casework
∣A∣=∣total∣−∣not A∣|A| = |\text{total}| - |\text{not }A|

What it means. Sometimes it is easier to count what you do not want.

Example. At least one head in 33 flips: 1−(12)3=781-\left(\tfrac12\right)^3=\tfrac78.

Why it works. Every outcome is either in AA or not, and never both, so the two counts partition the whole set and must add to the total.

Tip. Split into cases that are disjoint and exhaustive — no overlap, nothing missed — then add the case counts.