Skip to content
Combinatorics · Chapter 4

Principle of Inclusion and Exclusion

Count everything in A or B (or C, or more) without counting anything twice: add the sets, subtract the overlaps, add back, and pair it with complementary counting.

You'll need
open on YouTube
4.00%

Inclusion and Exclusion

In this section you will be able to count what is in at least one of several sets: add the sets, subtract the overlaps, add back, and keep alternating.

How many numbers from 1 to 100 are divisible by 2 or 7? There are 50 even numbers and 14 multiples of 7. But 64 is too many: 14, 28 and 42 are on both lists!

Adding the sizes of two sets counts their overlap twice. So subtract the overlap once. That is the principle of inclusion and exclusion, or PIE for short.

With three sets, an element in all three is added 3 times and subtracted 3 times. That leaves 0, so add it back once. With more sets, the signs keep alternating.

Look:PIE pairs well with complementary counting. When the bad cases are few, count them with PIE and subtract from the total.

Exploreplay first, formulas later

|×2 ∪ ×7| = 50 + 14 − 7 = 57; outside: 100 − 57 = 43

×2×7neither: 434377
Build the sum →
Over-count meter: times each region is counted
  • ×2 onlynot counted yet
  • ×7 onlynot counted yet
  • both ×2 and ×7not counted yet
|×2|50
|×7|14
|×2 ∩ ×7|7
everything100

Sum so far: 0. 0 regions over-counted, 3 not counted yet.

Name it

Definition 4.0.1 · Principle of Inclusion and Exclusion

The principle of inclusion and exclusion (PIE) is a counting technique that computes the number of elements that satisfy at least one of several properties, while making sure that elements satisfying more than one property are not counted twice.

Definition 4.0.2 · Union Symbol

∣A∪B∣|A \cup B| is the number of elements of the union of AA and BB: everything that is in AA or in BB (or both). Duplicates are only written once.

Definition 4.0.3 · Intersection Symbol

∣A∩B∣|A \cap B| is the number of elements of the intersection of AA and BB: only the elements that are in both sets.

Theorem 4.0.4 · Principle of Inclusion Exclusion for 2 Sets

Given two sets A1A_1 and A2A_2,

∣A1∪A2∣=∣A1∣+∣A2∣−∣A1∩A2∣.|A_1 \cup A_2| = |A_1| + |A_2| - |A_1 \cap A_2|.

Basically, we count the possibilities in the 2 "things" and subtract the duplicates.

Remark 4.0.5

When the number of cases that don't work is much less than the number of cases that do work, it often helps to use complementary counting together with PIE: count the bad cases with PIE, then subtract them from the total.

All 1024 (all subsets of {1, …, 10}) − 152 with all 5 evens or all 3 multiples of 3 = 872 with at most 4 evens and at most 2 multiples of 3

The question asks for:
All: 1,024 (all subsets of {1, …, 10})
{}{1}{2}{1,2}{3}{1,3}{2,3}{1,2,3}{4}{1,4}{2,4}{1,2,4}{3,4}{1,3,4}{2,3,4}{1,2,3,4}{5}{1,5}{2,5}{1,2,5}{3,5}{1,3,5}{2,3,5}{1,2,3,5}{4,5}{1,4,5}{2,4,5}{1,2,4,5}{3,4,5}{1,3,4,5}{2,3,4,5}{1,2,3,4,5}{6}{1,6}{2,6}{1,2,6}{3,6}{1,3,6}{2,3,6}{1,2,3,6}{4,6}{1,4,6}{2,4,6}{1,2,4,6}{3,4,6}{1,3,4,6}{2,3,4,6}{1,2,3,4,6}{5,6}{1,5,6}{2,5,6}{1,2,5,6}{3,5,6}{1,3,5,6}{2,3,5,6}{1,2,3,5,6}{4,5,6}{1,4,5,6}{2,4,5,6}{1,2,4,5,6}{3,4,5,6}{1,3,4,5,6}{2,3,4,5,6}{1,2,3,4,5,6}{7}{1,7}{2,7}{1,2,7}{3,7}{1,3,7}{2,3,7}{1,2,3,7}{4,7}{1,4,7}{2,4,7}{1,2,4,7}{3,4,7}{1,3,4,7}{2,3,4,7}{1,2,3,4,7}{5,7}{1,5,7}{2,5,7}{1,2,5,7}{3,5,7}{1,3,5,7}{2,3,5,7}{1,2,3,5,7}{4,5,7}{1,4,5,7}{2,4,5,7}{1,2,4,5,7}{3,4,5,7}{1,3,4,5,7}{2,3,4,5,7}{1,2,3,4,5,7}{6,7}{1,6,7}{2,6,7}{1,2,6,7}{3,6,7}{1,3,6,7}{2,3,6,7}{1,2,3,6,7}{4,6,7}{1,4,6,7}{2,4,6,7}{1,2,4,6,7}{3,4,6,7}{1,3,4,6,7}{2,3,4,6,7}{1,2,3,4,6,7}{5,6,7}{1,5,6,7}{2,5,6,7}{1,2,5,6,7}{3,5,6,7}{1,3,5,6,7}{2,3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9,10}{2,4,5,6,7,8,9,10}{1,2,4,5,6,7,8,9,10}{3,4,5,6,7,8,9,10}{1,3,4,5,6,7,8,9,10}{2,3,4,5,6,7,8,9,10}{1,2,3,4,5,6,7,8,9,10}
All: 1,024
We want: at most 4 evens and at most 2 multiples of 3
Count the opposite with PIE
  • 32 contain all 5 evens
  • + 128 contain all 3 multiples of 3
  • − 8 contain both families

All: 1,024 (all subsets of {1, …, 10})

Subsets of {1, …, 10}: the bad ones contain every even number or every multiple of 3.

Theorem 4.0.6 · Principle of Inclusion Exclusion for 3 Sets

Given three sets A1A_1, A2A_2, A3A_3,

∣A1∪A2∪A3∣=∣A1∣+∣A2∣+∣A3∣−∣A1∩A2∣−∣A1∩A3∣−∣A2∩A3∣+∣A1∩A2∩A3∣.\begin{aligned}|A_1 \cup A_2 \cup A_3| ={}& |A_1| + |A_2| + |A_3| \\ &- |A_1 \cap A_2| - |A_1 \cap A_3| - |A_2 \cap A_3| \\ &+ |A_1 \cap A_2 \cap A_3|.\end{aligned}

Count the possibilities in the 3 "things", subtract the duplicates in all 3 pairs of sets, then add back the elements that are in all 3 sets.

|Art ∪ Band ∪ Chess| = 10 + 9 + 8 − 4 − 3 − 3 + 1 = 18; outside: 25 − 18 = 7

ArtBandChessneither: 74333221
Build the sum →
Over-count meter: times each region is counted
  • Art onlynot counted yet
  • Band onlynot counted yet
  • Chess onlynot counted yet
  • Art and Band onlynot counted yet
  • Art and Chess onlynot counted yet
  • Band and Chess onlynot counted yet
  • all threenot counted yet
|Art|10
|Band|9
|Chess|8
|Art ∩ Band|4
|Art ∩ Chess|3
|Band ∩ Chess|3
|Art ∩ Band ∩ Chess|1
everything25

Sum so far: 0. 0 regions over-counted, 7 not counted yet.

Theorem 4.0.7 · Principle of Inclusion Exclusion Generalized

If A1,A2,…,AnA_1, A_2, \ldots, A_n are finite sets, then

∣⋃i=1nAi∣=∑i=1n∣Ai∣−∑i<j∣Ai∩Aj∣+∑i<j<k∣Ai∩Aj∩Ak∣−⋯+(−1)n−1∣A1∩⋯∩An∣.\left|\bigcup_{i=1}^{n} A_i\right| = \sum_{i=1}^{n} |A_i| - \sum_{i<j} |A_i \cap A_j| + \sum_{i<j<k} |A_i \cap A_j \cap A_k| - \cdots + (-1)^{n-1} |A_1 \cap \cdots \cap A_n|.

Add the singles, subtract the pairs, add the triples, and keep alternating.

4 sets, 15 terms; an element in 3 sets is counted 3 − 3 + 1 − 0 = 1 time

sets4
element is in3
PIE rounds for 4 sets
RoundSignTerms★ in★ count
singles+4··
pairs−6··
triples+4··
quadruples−1··
★ counted 0×

4 sets give 15 terms in all. Change “element is in”: after the last round the count is always exactly 1.

4 sets. An element in 3 of them has not been counted yet.

Watch itpredict, then reveal

Example 4.1

Find how many numbers from 1 to 100 (inclusive) are divisible by 2 or 7.

Multiples overlap (its total is revealed at the end of the example)

up to100
×281624324048566472808896×714284256708498
Where do the lines first meet?

Multiples of 2 and 7 up to 100.

  1. 1

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

    Predict first:

Example 4.2

AIME

Many states use a sequence of three letters followed by a sequence of three digits as their standard license-plate pattern. Given that each three-letter three-digit arrangement is equally likely, the probability that such a license plate will contain at least one palindrome (a three-letter arrangement or a three-digit arrangement that reads the same left-to-right as it does right-to-left) is mn\dfrac{m}{n}, where mm and nn are relatively prime positive integers. Find m+nm + n.

  1. 1

    What is the probability that the three letters form a palindrome?

    Predict first:
open on YouTube

Example 4.3

Omega Learn

How many subsets of the set {1,2,3,4,5,6,7,8,9,10}\{1, 2, 3, 4, 5, 6, 7, 8, 9, 10\} have at most 4 even numbers and at most 2 elements that are multiples of 3?

Two-set Venn diagram (its total is revealed at the end of the example)

ET????
Build the sum →
Over-count meter: times each region is counted
  • E onlynot counted yet
  • T onlynot counted yet
  • both E and Tnot counted yet

Sum so far: 0. 0 regions over-counted, 3 not counted yet.

  1. 1

    How can we apply PIE here? Should we count the good subsets or the bad ones?

    Predict first:
    Click a choice or type its letter (A–E).

Example 4.4

Omega Learn

How many different ways are there to arrange the letters in the word LOLLIPOP if each of the L's must be next to an O?

  1. 1

    There are 3 L's but only 2 O's. Each O has at most 2 neighbors. What does that force?

open on YouTube

Example 4.5

AIME

Let SS be a set with six elements. Let P\mathcal{P} be the set of all subsets of SS. Subsets AA and BB of SS, not necessarily distinct, are chosen independently and at random from P\mathcal{P}. The probability that BB is contained in one of AA or S−AS - A is mnr\dfrac{m}{n^r}, where mm, nn, and rr are positive integers, nn is prime, and mm and nn are relatively prime. Find m+n+rm + n + r. (The set S−AS - A is the set of all elements of SS which are not in AA.)

Subset switches (its total is revealed at the end of the example)

Elements6

Press an element to move it to the next region. Allowed: A only, A and B, neither.

A
{1, 2, 4, 6}
B
{1, 4}
A ∪ B
{1, 2, 4, 6}
A ∩ B
{1, 4}

Work out the count first; the walkthrough reveals it.

A = {1, 2, 4, 6}, B = {1, 4}.

  1. 1

    How many ways are there to choose AA and BB so that BB is contained entirely in AA?

    Predict first:

Example 4.6

How many numbers less than or equal to 193 are multiples of 2, 3, or 5?

Three-set Venn diagram (its total is revealed at the end of the example)

×2×3×5????????
Build the sum →
Over-count meter: times each region is counted
  • ×2 onlynot counted yet
  • ×3 onlynot counted yet
  • ×5 onlynot counted yet
  • ×2 and ×3 onlynot counted yet
  • ×2 and ×5 onlynot counted yet
  • ×3 and ×5 onlynot counted yet
  • all threenot counted yet

Sum so far: 0. 0 regions over-counted, 7 not counted yet.

  1. 1

    How many numbers up to 193 are divisible by 2?

    Predict first:

Example 4.7

AMC 8

Five different awards are to be given to three students. Each student will receive at least one award. In how many different ways can the awards be distributed?

Three-set Venn diagram (its total is revealed at the end of the example)

S1S2S3????????
Build the sum →
Over-count meter: times each region is counted
  • S1 onlynot counted yet
  • S2 onlynot counted yet
  • S3 onlynot counted yet
  • S1 and S2 onlynot counted yet
  • S1 and S3 onlynot counted yet
  • S2 and S3 onlynot counted yet
  • all threenot counted yet

Sum so far: 0. 0 regions over-counted, 6 not counted yet.

  1. 1

    Ignore the rule. In how many ways can 5 different awards go to 3 students?

    Predict first:
open on YouTube

Example 4.8

Modified AIME

Call a set SS product-free if there do not exist a,b,c∈Sa, b, c \in S (not necessarily distinct) such that ab=cab = c. For example, the empty set and the set {16,20}\{16, 20\} are product-free, whereas the sets {4,16}\{4, 16\} and {2,8,16}\{2, 8, 16\} are not product-free. Find the number of product-free subsets of the set {1,2,3,4,…,7,8,9}\{1, 2, 3, 4, \ldots, 7, 8, 9\}.

  1. 1

    Can 1 be in a product-free set?

    Predict first:
    Click a choice or type its letter (A–E).
open on YouTube

Example 4.9

AIME

Each unit square of a 3-by-3 unit-square grid is to be colored either blue or red. For each square, either color is equally likely to be used. The probability of obtaining a grid that does not have a red 2×22 \times 2 square is mn\dfrac{m}{n}, where mm and nn are relatively prime positive integers. Find m+nm + n.

PIE for n sets (its total is revealed at the end of the example)

?????????
9 free squares → 29 = 512
PIE rounds for 4 sets
RoundWaysColoringsTotal
+ singles4··
− pairs6··
+ triples4··
− quadruples1··

Blocks none red: 0 squares forced, 9 free, 2^9 = 512 colorings.

  1. 1

    Should we count grids without a red 2×22 \times 2 square directly?

    Predict first:
    Click a choice or type its letter (A–E).

Contest cornerreal contest problems

Problem 4.1.1

AIME

This problem also appears in the book as 4.2.

Many states use a sequence of three letters followed by a sequence of three digits as their standard license-plate pattern. Given that each three-letter three-digit arrangement is equally likely, the probability that such a license plate will contain at least one palindrome (a three-letter arrangement or a three-digit arrangement that reads the same left-to-right as it does right-to-left) is mn\dfrac{m}{n}, where mm and nn are relatively prime positive integers. Find m+nm + n.

Problem 4.1.2

AMC 10

Seven distinct pieces of candy are to be distributed among three bags. The red bag and the blue bag must each receive at least one piece of candy; the white bag may remain empty. How many arrangements are possible?

Problem 4.1.3

AMC 10

In how many ways can the sequence 1,2,3,4,51, 2, 3, 4, 5 be rearranged so that no three consecutive terms are increasing and no three consecutive terms are decreasing?

Problem 4.1.4

AMC 10

Ang, Ben, and Jasmin each have 5 blocks, colored red, blue, yellow, white, and green; and there are 5 empty boxes. Each of the people randomly and independently of the other two people places one of their blocks into each box. The probability that at least one box receives 3 blocks all of the same color is mn\dfrac{m}{n}, where mm and nn are relatively prime positive integers. What is m+nm + n?

Checkpoint for section 4.0

Get 2 of 3 right to master this section. One try each, no hints.
1

How many numbers from 1 to 60 are divisible by 3 or 4?

2

In a class of 30 students, 18 play soccer, 15 play basketball and 8 play both. How many play neither?

3

How many numbers from 1 to 30 are divisible by 2, 3 or 5?

4.1

Practice Problems

In this section you will be able to use PIE on contest problems, from AMC 10 warm-ups to AIME challenges.

Time for the harder ones. Each problem hides a union you need to count, or the complement of one. Find the sets first, then let PIE do the work.

The last three problems are AIME challenges. Each has three hints if you get stuck.

Want every problem from this chapter on one page? Open the problem set.

Contest cornerreal contest problems

Problem 4.1.5

AMC 10

This problem also appears in the book as 4.1.3.

In how many ways can the sequence 1,2,3,4,51, 2, 3, 4, 5 be rearranged so that no three consecutive terms are increasing and no three consecutive terms are decreasing?

Problem 4.1.6(additional)

AIME

Find the number of positive integers that are divisors of at least one of 101010^{10}, 15715^7, 181118^{11}.

Problem 4.1.7(additional)

AIME

In a five-team tournament, each team plays one game with every other team. Each team has a 50%50\% chance of winning any game it plays. (There are no ties.) Let mn\dfrac{m}{n} be the probability that the tournament will produce neither an undefeated team nor a winless team, where mm and nn are relatively prime integers. Find m+nm + n.

Problem 4.1.8(additional)

AIMEChallenge

Call a set SS product-free if there do not exist a,b,c∈Sa, b, c \in S (not necessarily distinct) such that ab=cab = c. For example, the empty set and the set {16,20}\{16, 20\} are product-free, whereas the sets {4,16}\{4, 16\} and {2,8,16}\{2, 8, 16\} are not product-free. Find the number of product-free subsets of the set {1,2,3,4,…,7,8,9,10}\{1, 2, 3, 4, \ldots, 7, 8, 9, 10\}.

Problem 4.1.9(additional)

AIMEChallenge

Define a regular nn-pointed star to be the union of nn line segments P1P2,P2P3,…,PnP1P_1P_2, P_2P_3, \ldots, P_nP_1 such that

  1. the points P1,P2,…,PnP_1, P_2, \ldots, P_n are coplanar and no three of them are collinear,
  2. each of the nn line segments intersects at least one of the other line segments at a point other than an endpoint, all of the angles at P1,P2,…,PnP_1, P_2, \ldots, P_n are congruent,
  3. all of the nn line segments P1P2,P2P3,…,PnP1P_1P_2, P_2P_3, \ldots, P_nP_1 are congruent, and the path P1P2,P2P3,…,PnP1P_1P_2, P_2P_3, \ldots, P_nP_1 turns counterclockwise at an angle of less than 180 degrees at each vertex.

There are no regular 3-pointed, 4-pointed, or 6-pointed stars. All regular 5-pointed stars are similar, but there are two non-similar regular 7-pointed stars. How many non-similar regular 1000-pointed stars are there?

Problem 4.1.10(additional)

AIMEChallenge

While watching a show, Ayako, Billy, Carlos, Dahlia, Ehuang, and Frank sat in that order in a row of six chairs. During the break, they went to the kitchen for a snack. When they came back, they sat on those six chairs in such a way that if two of them sat next to each other before the break, then they did not sit next to each other after the break. Find the number of possible seating orders they could have chosen after the break.