Overview

The Principle of Inclusion-Exclusion (abbreviated PIE) provides an organized method/formula to find the number of elements in the union of a given group of sets, the size of each set, and the size of all possible intersections among the sets. When using PIE, one should understand how to strategically overcount and undercount, in the end making sure every element is counted once and only once. In particular, memorizing a formula for PIE is a bad idea for problem solving. Hence, when one wants to count elements belonging to at least one of several sets, the inclusion-exclusion principle fixes this by alternately adding and subtracting overlaps.

Key Ideas

  • Always, and always define your sets precisely before writing any formula, to avoid confusion.
  • Many times in a problem, the complement is often cleaner and easier to calculate, especially in "at least" problems. Instead of ABC|A \cup B \cup C|, compute UAcBcCc|U| - |A^c\cap B^c \cap C^c|.
  • Utilize this visually through a Venn diagram.
  • For two sets: AB=A+BAB|A \cup B| = |A| + |B| - |A \cap B|.
  • You can apply the formula directly to probabilities: P(AB)=P(A)+P(B)P(AB)P(A \cup B) = P(A) + P(B) - P(A \cap B).
  • Exactly one of AA, BB equals A+B2AB|A| + |B| - 2|A \cap B|.

Core Skills

  1. Two-Set Formula

For any two finite sets AA and BB,

AB=A+BAB.|A \cup B| = |A| + |B| - |A \cap B|.

Elements only in AA are counted once. Elements only in BB are counted once. Elements in both are counted twice by A+B|A|+|B|, so subtracting AB|A \cap B| makes the double-counted only 1. In a venn diagram, we draw two overlapping circles and verify each of the three regions is counted exactly once.

  1. Three-Set Formula

For sets AA, BB, CC,

ABC=A+B+CABACBC+ABC.|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C|.

This process is the same for with the two-set formula but with one extra set.

  1. Complement

When "at least one" is harder to count directly, we count "none" instead, and subtract from U (total)

None of A,B,CA, B, C:

UABC|U| - |A \cup B \cup C|

Tip: Choose whichever side has simpler intersections, as it is useful for calculations.

  1. Divisibility

To count integers in [1,n][1, n] divisible by aa or bb, we utilize the same formula but within "divisibility" ideas.

na+nbnlcm(a,b)\left\lfloor \frac{n}{a} \right\rfloor + \left\lfloor \frac{n}{b} \right\rfloor - \left\lfloor \frac{n}{lcm(a,b)} \right\rfloor

An integer is divisible by both aa and bb if and only if it is divisible by lcm(a,b)\text{lcm}(a, b) — not abab (those differ when gcd(a,b)>1\gcd(a,b) > 1).

Worked Example - Core

How many integers from 1 to 100 are divisible by 2 or 3?

Let AA = multiples of 2 in [1,100][1,100] and BB = multiples of 3 in [1,100][1,100]. The intersection ABA \cap B is multiples of lcm(2,3)=6\text{lcm}(2,3) = 6.

A=1002=50,B=1003=33,AB=1006=16.|A| = \left\lfloor \tfrac{100}{2} \right\rfloor = 50, \quad |B| = \left\lfloor \tfrac{100}{3} \right\rfloor = 33, \quad |A \cap B| = \left\lfloor \tfrac{100}{6} \right\rfloor = 16.

Hence, AB=50+3316=67.|A \cup B| = 50 + 33 - 16 = 67.

Whenever the question states "divisible by aa or bb", define sets by divisibility, and use lcm\text{lcm} for the intersection, and apply the two-set formula.

  1. "Exactly one"

When a question states exactly one of AA, BB equals A+B2AB|A| + |B| - 2|A \cap B|.

Example 1: Three Overlapping identities

In a school of 200 students, 80 play chess, 60 play Go, and 50 play Scrabble. 30 play chess and Go, 20 play chess and Scrabble, 15 play Go and Scrabble, and 10 play all three. How many play at least one game?

CGS=80+60+50302015+10=135.|C \cup G \cup S| = 80 + 60 + 50 - 30 - 20 - 15 + 10 = 135. To find how many play none? 200135=65200 - 135 = 65. It is important to always check which question is being asked.

Example 2: Using Complement

What is the probability that when rolling two fair dice, at least one shows a number greater than 4?

Taking the complement, which is both dice showing 4\leq 4:

P(4on both dice)=(46)2=49,P(at least one>4)=149=59.P(\le 4 \text{on both dice}) = \left(\frac{4}{6}\right)^2 = \frac{4}{9}, \qquad P(\text{at least one} > 4) = 1 - \frac{4}{9} = \frac{5}{9}.

Hence we see that the complement is almost always faster than applying PIE directly.

Example 3: "Exactly One"

Out of 40 students, 18 are in the math club, 14 are in the robotics club, and 6 are in both. How many are in exactly one club?

A only+B only=(186)+(146)=12+8=20|A \text{ only}| + |B \text{ only}| = (18-6) + (14-6) = 12 + 8 = 20.

Or use the formula directly: A+B2AB=18+1412=20|A| + |B| - 2|A \cap B| = 18 + 14 - 12 = 20.

Strategy Checklist

  • First, always define each set precisely before writing any formula, and read the problem carefully.
  • Identify the universal set (UU) and its size.
  • Write out all pairwise and triple intersections before substituting.
  • For divisibility, use lcm\text{lcm} for intersections.
  • Always check in PIE if each element end up counted exactly once?
  • Is "exactly one" or "at least two" what's being asked? If so, one should adjust accordingly.

Common Pitfalls

  • Adding without subtracting overlaps. For instance, ABA+B|A \cup B| \neq |A| + |B| in general.
  • Forgetting to add ABC|A \cap B \cap C| back in the three-set formula.
  • Putting a - sign on the triple intersection instead of ++.
  • Using abab instead of lcm(a,b)\text{lcm}(a,b) for divisibility intersections.
  • Confusing "or" (\cup, at least one) with "and" (\cap, both).
  • Misreading "exactly one" as "at least one", and subtracting the overlap twice.

Practice Problems

  1. How many integers from 1 to 6767 (inclusive) are divisible by at least one of 2, 3, or 5?
  2. How many integers from 1 to 6767 (inclusive) are divisible by exactly one of 2, 3, or 5? (Notice the difference between 1 and 2).
  3. At Harvard University, there are 670 students. 60 students take math, 45 take chemistry, 30 take literature, 25 take math and chemistry, 15 take math and literature, 10 take chemistry and literature, and 5 take all three classes. How many students take none of the three classes?
  4. In a neighborhood of 120 silly kids, 51 play soccer, 39 play basketball, 31 play tennis, 9 play both soccer and basketball, 5 play both soccer and tennis, 4 play both basketball and tennis, and 2 play all three. How many students play exactly one sport?
  5. (HARD) How many strings of length four that can have only digits, 0, 1, or 2, have at least one 1, and one 2?
  6. (CHALLENGE) How many permutations of 6 have at least one of 1, 2, 3 in its correct (original) position?
StatusSourceProblem NameDifficultyTags
AMC 8Medium
Show TagsInclusion-Exclusion, LCM
AMC 8Easy
Show TagsInclusion-Exclusion, Sets
AMC 10Hard
Show TagsCombinatorics, Inclusion-Exclusion, Probability
AIMEHard
Show TagsCounting, Inclusion-Exclusion, Sets
AMC 12Hard
Show TagsCounting, Inclusion-Exclusion, Sets
AIMEHard
Show TagsCounting, Inclusion-Exclusion, Tiling

Module Progress:

Join the AoPS Community!

Stuck on a problem, or don't understand a module? Join the AoPS community and get help from other math contest students.