Agent Work: HW7: Dynamic Programming
Claude Sonnet 4.6 · COMP 182: Algorithmic Thinking
COMP 182: Algorithmic Thinking
Homework 7: Counting
Spring 2023
This homework is divided into three distinct parts. When you submit, you will need a file for each part.
---
Part 1
Problem 1 [7 pts]
How many bit strings of length 10 either start with 000 or end with 111?
Show your work.
---
Problem 2 [7 pts]
How many positive integers less than 1,000,000 have exactly one digit equal to 9 and have a sum of digits equal to 13?
Show your work.
---
Problem 3 [7 pts]
How many solutions are there to the inequality
$$x_1 + x_2 + x_3 \leq 11,$$
where $x_1$, $x_2$, and $x_3$ are nonnegative integers?
Show your work.
---
Problem 4 [8 pts]
Prove, without using induction, that in any set of $n + 1$ positive integers not exceeding $2n$ there must be two that are relatively prime.
---
Part 2
Problem 1 [8 pts]
Suppose that $p$ and $q$ are prime numbers, that $p \neq q$, and that $n = pq$. What is the number of positive integers not exceeding $n$ that are relatively prime to $n$?
Show your work.
---
Problem 2 [21 pts]
In celebration of the end of the semester, all the students and instructors in COMP 182 were invited to take a group picture. Assume that there are $n$ students and $m$ instructors. Exactly one instructor is designated as the lead instructor.
Show your work in each part.
(a) [7 pts]
How many ways are there to arrange all the students and instructors in a line such that all students are standing next to each other (no instructors between them)?
(b) [7 pts]
How many ways are there to arrange all the students and instructors in a line such that no two instructors are standing next to each other (the number of students in the course is so large that it allows us to consider this!)?
(c) [7 pts]
How many ways are there to arrange all the students and instructors in a line such that no student is standing next to the lead instructor?
---
Part 3
Problem 1 [14 pts]
How many ways are there to place 80 identical balls in 5 distinct bins such that no bin has more than 24 balls?
---
Problem 2 [14 pts]
What is the number of permutations of the letters in the word INDISTINGUISHABLE such that the strings GIT, TIN, and NAB do not appear in the permutation?
---
Problem 3 [14 pts]
How many 1-1 functions $f : \{1, \ldots, 20\} \to \{1, \ldots, 80\}$ without a fixed point are there?
A function $f : A \to B$ has a fixed point if there exists an $a \in A$ such that $f(a) = a$.
---
Point Distribution Summary
| Part | Problem | Points |
|---|---|---|
| 1 | 1 | 7 |
| 1 | 2 | 7 |
| 1 | 3 | 7 |
| 1 | 4 | 8 |
| 2 | 1 | 8 |
| 2 | 2a | 7 |
| 2 | 2b | 7 |
| 2 | 2c | 7 |
| 3 | 1 | 14 |
| 3 | 2 | 14 |
| 3 | 3 | 14 |
| Total | 100 |
# COMP182 Homework 7
## Student Responses
<!-- Write your solutions below. Add sections for each problem as needed. -->
<!-- Use proper mathematical notation where applicable. -->
[Your solutions here]
COMP182 Homework 7
Student Responses
---
Part 1
Problem 1
How many bit strings of length 10 either start with 000 or end with 111?
Let A = bit strings of length 10 starting with 000. Let B = bit strings of length 10 ending with 111.
- |A| = 2^7 = 128 (first 3 bits fixed, remaining 7 are free)
- |B| = 2^7 = 128 (last 3 bits fixed, remaining 7 are free)
- |A ∩ B| = 2^4 = 16 (first 3 and last 3 bits all fixed, middle 4 are free)
By inclusion-exclusion:
---
Problem 2
How many positive integers less than 1,000,000 have exactly one digit equal to 9 and have a sum of digits equal to 13?
Represent each number as a 6-digit string (with leading zeros allowed), ranging from 000000 to 999999. Since we need digit sum 13, the value 000000 is automatically excluded (digit sum 0), so all counted solutions are positive integers.
We need exactly one digit equal to 9 and total digit sum 13.
- Choose which of the 6 positions holds the 9: C(6,1) = 6 ways.
- The remaining 5 digits must each be in {0, 1, …, 8} and sum to 13 − 9 = 4.
- Since the remaining digits sum to only 4, no digit can reach 9, so the constraint d_i ≤ 8 is automatically satisfied.
- Number of non-negative integer solutions to d_1 + d_2 + d_3 + d_4 + d_5 = 4 with no upper bound constraint: C(4 + 5 − 1, 5 − 1) = C(8, 4) = 70.
Total = 6 × 70 = 420
---
Problem 3
How many solutions are there to x_1 + x_2 + x_3 ≤ 11, where x_1, x_2, x_3 are nonneg integers?
Introduce a slack variable x_4 ≥ 0 to convert the inequality to an equality:
x_1 + x_2 + x_3 + x_4 = 11
The number of non-negative integer solutions is:
C(11 + 4 − 1, 4 − 1) = C(14, 3) = 14 · 13 · 12 / 6 = 364
---
Problem 4
Prove, without using induction, that in any set of n + 1 positive integers not exceeding 2n there must be two that are relatively prime.
Proof. Partition the set {1, 2, …, 2n} into n pairs of consecutive integers:
{1, 2}, {3, 4}, {5, 6}, …, {2n−1, 2n}.
These n pairs are disjoint and cover all of {1, 2, …, 2n}.
Given any set S of n + 1 positive integers not exceeding 2n, by the Pigeonhole Principle, at least two elements of S must belong to the same pair {2k−1, 2k} for some k.
Call these two elements 2k−1 and 2k. They are consecutive integers, so gcd(2k−1, 2k) = 1: if d divides both 2k−1 and 2k, then d divides (2k) − (2k−1) = 1, so d = 1.
Therefore, the set S contains two elements that are relatively prime. □
---
Part 2
Problem 1
What is the number of positive integers not exceeding n = pq that are relatively prime to n?
This is Euler's totient function φ(pq). We count by exclusion.
Among {1, 2, …, pq}, integers not coprime to pq are those divisible by p or by q.
- Multiples of p in {1, …, pq}: p, 2p, …, qp → q multiples
- Multiples of q in {1, …, pq}: q, 2q, …, pq → p multiples
- Multiples of both p and q (i.e., multiples of pq): just pq → 1 multiple
By inclusion-exclusion, integers not coprime to pq: q + p − 1.
Therefore:
φ(pq) = pq − (p + q − 1) = pq − p − q + 1 = (p − 1)(q − 1)
---
Problem 2
Assume n students and m instructors, with one designated lead instructor L. Total people: n + m.
Part (a)
All students standing next to each other (no instructors between them).
Treat all n students as a single block. We then have m instructors + 1 student block = m + 1 objects to arrange in a line.
- Arrange m + 1 objects: (m + 1)! ways
- Arrange n students within the block: n! ways
Total: (m + 1)! · n!
---
Part (b)
No two instructors standing next to each other.
First arrange the n students in a line: n! ways. This creates n + 1 gaps (including the two ends):
_ S _ S _ … _ S _
To ensure no two instructors are adjacent, place at most one instructor per gap. Choose m of the n + 1 gaps and assign the m distinct instructors (in order):
- Choose m gaps from n + 1: C(n + 1, m) ways
- Arrange m instructors in the chosen gaps: m! ways
Total: n! · C(n + 1, m) · m!
---
Part (c)
No student is standing next to the lead instructor L.
Use inclusion-exclusion. Let A_i = set of all arrangements where student i is adjacent to L (for i = 1, …, n). We want (n+m)! − |A_1 ∪ … ∪ A_n|.
Computing |A_i|: Treat {student i, L} as a block with 2 internal orderings. Then we have n + m − 1 units. |A_i| = 2 · (n + m − 1)!.
Computing |A_i ∩ A_j| for i ≠ j: Both students i and j must be adjacent to L, meaning L is between them. The block (i–L–j or j–L–i) has 2 orderings and gives n + m − 2 units. |A_i ∩ A_j| = 2 · (n + m − 2)!.
Computing |A_i ∩ A_j ∩ A_k|: L can have at most 2 neighbors, so three students cannot all be adjacent to L simultaneously. This is 0.
By inclusion-exclusion:
= 2n(n+m−1)! − n(n−1)(n+m−2)!
Valid arrangements = (n+m)! − 2n(n+m−1)! + n(n−1)(n+m−2)!
Factor out (n+m−2)!:
= (n+m−2)! · [(n+m)(n+m−1) − 2n(n+m−1) + n(n−1)]
Expand the bracket:
- (n+m)(n+m−1) = n² + 2mn + m² − n − m
- 2n(n+m−1) = 2n² + 2mn − 2n
- n(n−1) = n² − n
Sum: (n² + 2mn + m² − n − m) − (2n² + 2mn − 2n) + (n² − n) = m² − m = m(m−1)
Total: m(m − 1)(n + m − 2)!
---
Part 3
Problem 1
Place 80 identical balls in 5 distinct bins, no bin has more than 24 balls.
Let x_i = number of balls in bin i. We need x_1 + x_2 + x_3 + x_4 + x_5 = 80 with 0 ≤ x_i ≤ 24.
Without restriction: C(84, 4) ways.
Let A_i = event that bin i has ≥ 25 balls. Use inclusion-exclusion to subtract violations.
|A_i|: Substitute y_i = x_i − 25 ≥ 0. Sum becomes 55. Count = C(59, 4). There are C(5,1) = 5 such terms.
|A_i ∩ A_j|: Two bins each ≥ 25, sum becomes 30. Count = C(34, 4). There are C(5,2) = 10 such terms.
|A_i ∩ A_j ∩ A_k|: Three bins each ≥ 25, sum becomes 5. Count = C(9, 4). There are C(5,3) = 10 such terms.
|A_i ∩ A_j ∩ A_k ∩ A_l|: Four bins each ≥ 25 requires at least 100 balls > 80. Impossible. Count = 0.
Computing the binomial coefficients:
- C(84, 4) = (84 · 83 · 82 · 81) / 24 = 46,308,024 / 24 = 1,929,501
- C(59, 4) = (59 · 58 · 57 · 56) / 24 = 10,923,024 / 24 = 455,126
- C(34, 4) = (34 · 33 · 32 · 31) / 24 = 1,113,024 / 24 = 46,376
- C(9, 4) = (9 · 8 · 7 · 6) / 24 = 3024 / 24 = 126
By inclusion-exclusion:
= 1,929,501 − 2,275,630 + 463,760 − 1,260 = 116,371
---
Problem 2
Permutations of INDISTINGUISHABLE such that GIT, TIN, and NAB do not appear.
Step 1: Count letters in INDISTINGUISHABLE.
I–N–D–I–S–T–I–N–G–U–I–S–H–A–B–L–E (17 letters total):
- I × 4, N × 2, S × 2, D × 1, T × 1, G × 1, U × 1, H × 1, A × 1, B × 1, L × 1, E × 1
Total permutations = 17! / (4! · 2! · 2!)
Step 2: Define events and overlap analysis.
Let A = permutations containing "GIT", B = permutations containing "TIN", C = permutations containing "NAB".
Key observations about overlaps (using letter multiplicities):
- T appears only once. Both GIT and TIN require T, so if both appear, they must share T. The only overlap is GIT + TIN sharing T → GITIN (G–I–T–I–N).
- TIN ends with N; NAB starts with N. They can share N → TINAB (T–I–N–A–B), or use separate N's (N appears twice).
- GIT and NAB share no letters, so they always appear as separate blocks.
Step 3: Compute each term.
When treating a substring as a block, remove its letters from the pool and count permutations of (remaining letters + block) with appropriate repetition factors.
|A|: GIT block. Remaining: I×3, N×2, S×2, others×1. Units = 15.
|B|: TIN block. Remaining: I×3, N×1, S×2, others×1. Units = 15.
|C|: NAB block. Remaining: I×4, N×1, S×2, others×1. Units = 15.
|A ∩ B|: GIT and TIN must overlap as GITIN (only one T). GITIN block uses G×1, I×2, T×1, N×1. Remaining: I×2, N×1, S×2, others×1. Units = 13.
|A ∩ C|: GIT block + NAB block (no shared letters). Remaining: I×3, N×1, S×2, others×1. Units = 13.
|B ∩ C|: Two sub-cases (both valid since N appears twice):
- *Case 1 (overlap):* TINAB block (sharing N). Remaining: I×3, N×1, S×2, G×1, others×1. Units = 13. Count = 13! / (3! · 2!) = 518,918,400.
- *Case 2 (non-overlap):* TIN block + NAB block (each using its own N). Remaining: I×3, S×2, G×1, others×1. Units = 13. Count = 13! / (3! · 2!) = 518,918,400.
|A ∩ B ∩ C|: GIT and TIN must form GITIN; then NAB can share or not share N with GITIN:
- *Case 1 (overlap):* GITINAB block (G–I–T–I–N–A–B). Remaining: I×2, N×1, S×2, others×1. Units = 11. Count = 11! / (2! · 2!) = 9,979,200.
- *Case 2 (non-overlap):* GITIN block + NAB block (using the remaining N). Remaining: I×2, S×2, others×1. Units = 11. Count = 11! / (2! · 2!) = 9,979,200.
Step 4: Apply inclusion-exclusion.
= 54,486,432,000 + 108,972,864,000 + 27,243,216,000 − 1,556,755,200 − 518,918,400 − 1,037,836,800 + 19,958,400 = 190,702,512,000 − 3,113,510,400 + 19,958,400 = 187,608,960,000
Total permutations = 17! / (4! · 2! · 2!) = 3,705,077,376,000
Answer = 3,705,077,376,000 − 187,608,960,000 = 3,517,468,416,000
---
Problem 3
Number of 1-1 functions f : {1, …, 20} → {1, …, 80} with no fixed point.
A fixed point is a ∈ {1, …, 20} with f(a) = a (only elements 1 through 20 can be fixed points, since a must lie in both the domain and the codomain for f(a) = a to hold, and the domain is {1,…,20}).
Total injective functions: P(80, 20) = 80! / 60!
Apply inclusion-exclusion. Let A_i = set of injective functions where f(i) = i.
|A_i|: Fix f(i) = i; map remaining 19 domain elements injectively into 79 remaining codomain elements.
|A_i ∩ A_j| (i ≠ j): Fix f(i) = i and f(j) = j; remaining 18 elements map into 78 elements.
General k-fold intersection: Fix f(i_1) = i_1, …, f(i_k) = i_k; remaining 20−k elements map into 80−k elements.
By inclusion-exclusion, the number of injective functions with at least one fixed point is:
sum_{k=1}^{20} (−1)^{k+1} · C(20, k) · (80−k)! / 60!
Therefore, the number of injective functions with no fixed point is:
sum_{k=0}^{20} (−1)^k · C(20, k) · P(80−k, 20−k)
= sum_{k=0}^{20} (−1)^k · C(20, k) · (80−k)! / 60!
Expanding:
= P(80,20) − C(20,1)·P(79,19) + C(20,2)·P(78,18) − … + (−1)^{20}·C(20,20)·P(60,0)
= (1/60!) · sum_{k=0}^{20} (−1)^k · C(20, k) · (80−k)!
COMP 182 Homework 7 — Grading Report
---
Part 1
Problem 1 [7/7]
The student correctly applies inclusion-exclusion with sets A (start with 000) and B (end with 111). All intermediate values are correct (|A| = 128, |B| = 128, |A ∩ B| = 16), and the final answer of 240 matches the reference. Work is clearly shown.
- Logic correct: 4/4
- Final answer correct: 2/2
- Shows work: 1/1
---
Problem 2 [7/7]
The student uses a clever alternative approach: representing each number as a 6-digit string with leading zeros (000000–999999). This is valid because there is a bijection between positive integers less than 1,000,000 and 6-digit strings (excluding 000000, which has digit sum 0 and is automatically excluded). The student then chooses 1 of 6 positions for the 9 (C(6,1) = 6), and counts nonneg. integer solutions to the remaining 5 digits summing to 4 (C(8,4) = 70). Since 4 < 9, the upper-bound constraint is automatically satisfied. This approach avoids the rubric's more involved case analysis over 2–6 digit numbers while arriving at the same correct answer of 420.
- Logic correct: 4/4
- Final answer correct: 2/2
- Shows work: 1/1
---
Problem 3 [7/7]
The student uses the slack variable approach (listed as the alternative method in the rubric). Introducing x₄ ≥ 0 converts the inequality to x₁ + x₂ + x₃ + x₄ = 11, giving C(14, 3) = 364. Correct.
- Logic correct: 4/4
- Final answer correct: 2/2
- Shows work: 1/1
---
Problem 4 [8/8]
The student provides an elegant proof using the Pigeonhole Principle. They partition {1, 2, …, 2n} into n pairs of consecutive integers {1,2}, {3,4}, …, {2n−1, 2n}. With n+1 integers and only n pairs, by Pigeonhole at least two must fall in the same pair, making them consecutive. The student then proves consecutive integers are coprime (if d | k and d | k+1, then d | 1). This is a complete, correct proof — different from the rubric's contradiction-based approach but equally valid and arguably more direct.
- Full credit: 8/8
---
Part 2
Problem 1 [8/8]
The student correctly identifies this as Euler's totient function φ(pq). Using inclusion-exclusion: q multiples of p, p multiples of q, 1 multiple of pq. Result: pq − (p + q − 1) = (p−1)(q−1). Matches the reference solution exactly.
- Full credit: 8/8
---
Problem 2(a) [7/7]
Treats n students as a single block, yielding (m+1) objects to permute: (m+1)! ways. Students within the block: n! arrangements. Total: (m+1)! · n!. Correct.
- Logic correct: 3/3
- Final answer correct: 2/2
- Shows work: 2/2
---
Problem 2(b) [7/7]
The student uses a direct gap-filling approach: arrange n students (n! ways), creating n+1 gaps, choose m of them for instructors (C(n+1, m)), and arrange the m instructors (m! ways). Total: n! · C(n+1, m) · m!. This matches the rubric's answer derived via stars-and-bars.
- Logic correct: 3/3
- Final answer correct: 2/2
- Shows work: 2/2
---
Problem 2(c) [7/7]
The student uses inclusion-exclusion (different from the rubric's case analysis), defining A_i as arrangements where student i is adjacent to L. Key steps:
- |A_i| = 2(n+m−1)! (block of 2 with 2 orderings) ✓
- |A_i ∩ A_j| = 2(n+m−2)! (L between both students, block of 3 with 2 orderings) ✓
- |A_i ∩ A_j ∩ A_k| = 0 (L has at most 2 neighbors) ✓
The student then simplifies: (n+m)! − 2n(n+m−1)! + n(n−1)(n+m−2)! = (n+m−2)![(n+m)(n+m−1) − 2n(n+m−1) + n(n−1)]
I verified the algebra: the bracket simplifies to m² − m = m(m−1), giving m(m−1)(n+m−2)!.
This matches the rubric's answer: 2(m−1)(n+m−2)! + (m−1)(m−2)(n+m−2)! = (m−1)(n+m−2)![2 + (m−2)] = m(m−1)(n+m−2)!. ✓
- Logic correct: 3/3
- Final answer correct: 2/2
- Shows work: 2/2
---
Part 3
Problem 1 [14/14]
The student correctly identifies this as an inclusion-exclusion problem with upper bound constraints. All terms are computed correctly:
- Without restriction: C(84,4) = 1,929,501 ✓
- |A_i|: C(59,4) = 455,126, with C(5,1) = 5 terms ✓
- |A_i ∩ A_j|: C(34,4) = 46,376, with C(5,2) = 10 terms ✓
- |A_i ∩ A_j ∩ A_k|: C(9,4) = 126, with C(5,3) = 10 terms ✓
- Higher-order: 4×25 = 100 > 80, impossible ✓
- Final: 1,929,501 − 2,275,630 + 463,760 − 1,260 = 116,371 ✓
- Identifies inclusion-exclusion: 3/3
- |A_i| correct: 2/2
- |A_i ∩ A_j| correct: 2/2
- |A_i ∩ A_j ∩ A_k| correct: 2/2
- Higher-order empty: 2/2
- Final answer correct: 2/2
- Work shown: 1/1
---
Problem 2 [14/14]
This is a complex inclusion-exclusion problem with overlapping substrings, and the student handles it meticulously.
- Letter frequencies correctly identified: I(4), N(2), S(2), nine singletons ✓
- Total permutations: 17!/(4!·2!·2!) ✓
- |A|, |B|, |C|: All correctly computed with proper remaining multiplicities (e.g., GIT consumes one I, reducing I from 4→3; TIN consumes one I and one N) ✓
- Overlap analysis: The student correctly identifies that GIT and TIN must share T (only one T exists) forming GITIN; TIN and NAB can share N or not (N appears twice); GIT and NAB share no letters ✓
- Pairwise intersections: |A∩B| = 13!/(2!·2!), |A∩C| = 13!/(3!·2!), |B∩C| = 2 × 13!/(3!·2!) — all correct ✓
- Three-way intersection: |A∩B∩C| = 2 × 11!/(2!·2!) — correctly handles both GITINAB overlap and GITIN + NAB non-overlap cases ✓
- Numerical computation: Final answer 3,517,468,416,000 verified ✓
- Total permutations: 2/2
- |A|, |B|, |C|: 3/3
- Overlap identification: 3/3
- Pairwise intersections: 3/3
- Three-way intersection: 2/2
- Work shown: 1/1
---
Problem 3 [14/14]
The student sets up the inclusion-exclusion perfectly for derangement-like counting on injective functions.
- Total 1-1 functions: P(80,20) = 80!/60! ✓
- A_i defined correctly: f(i) = i as a fixed point ✓
- |A_i| = 79!/60! (fix one value, inject remaining 19 into 79 elements) ✓
- k-fold intersection: (80−k)!/60! (fix k values, inject remaining 20−k into 80−k elements) ✓
- Final formula: Σ_{k=0}^{20} (−1)^k C(20,k)(80−k)!/60! ✓
- Clear expansion showing all terms ✓
- Total 1-1 functions: 3/3
- Inclusion-exclusion setup: 3/3
- |A_i| correct: 2/2
- k-fold intersection: 3/3
- Final formula correct: 2/2
- Work shown: 1/1
---
Summary
| Part | Problem | Max | Score |
|---|---|---|---|
| 1 | 1 | 7 | 7 |
| 1 | 2 | 7 | 7 |
| 1 | 3 | 7 | 7 |
| 1 | 4 | 8 | 8 |
| 2 | 1 | 8 | 8 |
| 2 | 2a | 7 | 7 |
| 2 | 2b | 7 | 7 |
| 2 | 2c | 7 | 7 |
| 3 | 1 | 14 | 14 |
| 3 | 2 | 14 | 14 |
| 3 | 3 | 14 | 14 |
| Total | 100 | 100 |
Overall Comments: This is an outstanding submission. Every problem is solved correctly with clear, well-organized work. The student frequently employs alternative approaches to the reference solutions — Pigeonhole Principle for Part 1 Problem 4, the leading-zeros representation for Part 1 Problem 2, and inclusion-exclusion for Part 2 Problem 2(c) — all of which are mathematically sound and sometimes more elegant than the rubric's methods. The particularly impressive solutions are Part 3 Problem 2 (substring avoidance with careful overlap analysis) and Part 2 Problem 2(c) (clean factorization to m(m−1)(n+m−2)!).
Total: 100/100
diff --git a/writeup.md b/writeup.md
index b1e2070..c8153bc 100644
--- a/writeup.md
+++ b/writeup.md
@@ -2,8 +2,301 @@
## Student Responses
-<!-- Write your solutions below. Add sections for each problem as needed. -->
-<!-- Use proper mathematical notation where applicable. -->
+---
-[Your solutions here]
+## Part 1
+### Problem 1
+
+**How many bit strings of length 10 either start with 000 or end with 111?**
+
+Let A = bit strings of length 10 starting with 000.
+Let B = bit strings of length 10 ending with 111.
+
+- |A| = 2^7 = 128 (first 3 bits fixed, remaining 7 are free)
+- |B| = 2^7 = 128 (last 3 bits fixed, remaining 7 are free)
+- |A ∩ B| = 2^4 = 16 (first 3 and last 3 bits all fixed, middle 4 are free)
+
+By inclusion-exclusion:
+
+|A ∪ B| = |A| + |B| − |A ∩ B| = 128 + 128 − 16 = **240**
+
+---
+
+### Problem 2
+
+**How many positive integers less than 1,000,000 have exactly one digit equal to 9 and have a sum of digits equal to 13?**
+
+Represent each number as a 6-digit string (with leading zeros allowed), ranging from 000000 to 999999. Since we need digit sum 13, the value 000000 is automatically excluded (digit sum 0), so all counted solutions are positive integers.
+
+We need exactly one digit equal to 9 and total digit sum 13.
+
+- Choose which of the 6 positions holds the 9: C(6,1) = 6 ways.
+- The remaining 5 digits must each be in {0, 1, …, 8} and sum to 13 − 9 = 4.
+- Since the remaining digits sum to only 4, no digit can reach 9, so the constraint d_i ≤ 8 is automatically satisfied.
+- Number of non-negative integer solutions to d_1 + d_2 + d_3 + d_4 + d_5 = 4 with no upper bound constraint: C(4 + 5 − 1, 5 − 1) = C(8, 4) = 70.
+
+Total = 6 × 70 = **420**
+
+---
+
+### Problem 3
+
+**How many solutions are there to x_1 + x_2 + x_3 ≤ 11, where x_1, x_2, x_3 are nonneg integers?**
+
+Introduce a slack variable x_4 ≥ 0 to convert the inequality to an equality:
+
+x_1 + x_2 + x_3 + x_4 = 11
+
+The number of non-negative integer solutions is:
+
+C(11 + 4 − 1, 4 − 1) = C(14, 3) = 14 · 13 · 12 / 6 = **364**
+
+---
+
+### Problem 4
+
+**Prove, without using induction, that in any set of n + 1 positive integers not exceeding 2n there must be two that are relatively prime.**
+
+**Proof.** Partition the set {1, 2, …, 2n} into n pairs of consecutive integers:
+
+{1, 2}, {3, 4}, {5, 6}, …, {2n−1, 2n}.
+
+These n pairs are disjoint and cover all of {1, 2, …, 2n}.
+
+Given any set S of n + 1 positive integers not exceeding 2n, by the Pigeonhole Principle, at least two elements of S must belong to the same pair {2k−1, 2k} for some k.
+
+Call these two elements 2k−1 and 2k. They are consecutive integers, so gcd(2k−1, 2k) = 1: if d divides both 2k−1 and 2k, then d divides (2k) − (2k−1) = 1, so d = 1.
+
+Therefore, the set S contains two elements that are relatively prime. □
+
+---
+
+## Part 2
+
+### Problem 1
+
+**What is the number of positive integers not exceeding n = pq that are relatively prime to n?**
+
+This is Euler's totient function φ(pq). We count by exclusion.
+
+Among {1, 2, …, pq}, integers **not** coprime to pq are those divisible by p or by q.
+
+- Multiples of p in {1, …, pq}: p, 2p, …, qp → q multiples
+- Multiples of q in {1, …, pq}: q, 2q, …, pq → p multiples
+- Multiples of both p and q (i.e., multiples of pq): just pq → 1 multiple
+
+By inclusion-exclusion, integers not coprime to pq: q + p − 1.
+
+Therefore:
+
+φ(pq) = pq − (p + q − 1) = pq − p − q + 1 = **(p − 1)(q − 1)**
+
+---
+
+### Problem 2
+
+Assume n students and m instructors, with one designated lead instructor L. Total people: n + m.
+
+#### Part (a)
+
+**All students standing next to each other (no instructors between them).**
+
+Treat all n students as a single block. We then have m instructors + 1 student block = m + 1 objects to arrange in a line.
+
+- Arrange m + 1 objects: (m + 1)! ways
+- Arrange n students within the block: n! ways
+
+Total: **(m + 1)! · n!**
+
+---
+
+#### Part (b)
+
+**No two instructors standing next to each other.**
+
+First arrange the n students in a line: n! ways. This creates n + 1 gaps (including the two ends):
+
+_ S _ S _ … _ S _
+
+To ensure no two instructors are adjacent, place at most one instructor per gap. Choose m of the n + 1 gaps and assign the m distinct instructors (in order):
+
+- Choose m gaps from n + 1: C(n + 1, m) ways
+- Arrange m instructors in the chosen gaps: m! ways
+
+Total: **n! · C(n + 1, m) · m!**
+
+---
+
+#### Part (c)
+
+**No student is standing next to the lead instructor L.**
+
+Use inclusion-exclusion. Let A_i = set of all arrangements where student i is adjacent to L (for i = 1, …, n). We want (n+m)! − |A_1 ∪ … ∪ A_n|.
+
+**Computing |A_i|:** Treat {student i, L} as a block with 2 internal orderings. Then we have n + m − 1 units. |A_i| = 2 · (n + m − 1)!.
+
+**Computing |A_i ∩ A_j| for i ≠ j:** Both students i and j must be adjacent to L, meaning L is between them. The block (i–L–j or j–L–i) has 2 orderings and gives n + m − 2 units. |A_i ∩ A_j| = 2 · (n + m − 2)!.
+
+**Computing |A_i ∩ A_j ∩ A_k|:** L can have at most 2 neighbors, so three students cannot all be adjacent to L simultaneously. This is 0.
+
+By inclusion-exclusion:
+
+|A_1 ∪ … ∪ A_n| = C(n,1) · 2(n+m−1)! − C(n,2) · 2(n+m−2)!
+ = 2n(n+m−1)! − n(n−1)(n+m−2)!
+
+Valid arrangements = (n+m)! − 2n(n+m−1)! + n(n−1)(n+m−2)!
+
+Factor out (n+m−2)!:
+
+= (n+m−2)! · [(n+m)(n+m−1) − 2n(n+m−1) + n(n−1)]
+
+Expand the bracket:
+- (n+m)(n+m−1) = n² + 2mn + m² − n − m
+- 2n(n+m−1) = 2n² + 2mn − 2n
+- n(n−1) = n² − n
+
+Sum: (n² + 2mn + m² − n − m) − (2n² + 2mn − 2n) + (n² − n) = m² − m = m(m−1)
+
+Total: **m(m − 1)(n + m − 2)!**
+
+---
+
+## Part 3
+
+### Problem 1
+
+**Place 80 identical balls in 5 distinct bins, no bin has more than 24 balls.**
+
+Let x_i = number of balls in bin i. We need x_1 + x_2 + x_3 + x_4 + x_5 = 80 with 0 ≤ x_i ≤ 24.
+
+Without restriction: C(84, 4) ways.
+
+Let A_i = event that bin i has ≥ 25 balls. Use inclusion-exclusion to subtract violations.
+
+**|A_i|:** Substitute y_i = x_i − 25 ≥ 0. Sum becomes 55. Count = C(59, 4).
+There are C(5,1) = 5 such terms.
+
+**|A_i ∩ A_j|:** Two bins each ≥ 25, sum becomes 30. Count = C(34, 4).
+There are C(5,2) = 10 such terms.
+
+**|A_i ∩ A_j ∩ A_k|:** Three bins each ≥ 25, sum becomes 5. Count = C(9, 4).
+There are C(5,3) = 10 such terms.
+
+**|A_i ∩ A_j ∩ A_k ∩ A_l|:** Four bins each ≥ 25 requires at least 100 balls > 80. Impossible. Count = 0.
+
+Computing the binomial coefficients:
+
+- C(84, 4) = (84 · 83 · 82 · 81) / 24 = 46,308,024 / 24 = 1,929,501
+- C(59, 4) = (59 · 58 · 57 · 56) / 24 = 10,923,024 / 24 = 455,126
+- C(34, 4) = (34 · 33 · 32 · 31) / 24 = 1,113,024 / 24 = 46,376
+- C(9, 4) = (9 · 8 · 7 · 6) / 24 = 3024 / 24 = 126
+
+By inclusion-exclusion:
+
+|valid| = 1,929,501 − 5(455,126) + 10(46,376) − 10(126)
+ = 1,929,501 − 2,275,630 + 463,760 − 1,260
+ = **116,371**
+
+---
+
+### Problem 2
+
+**Permutations of INDISTINGUISHABLE such that GIT, TIN, and NAB do not appear.**
+
+**Step 1: Count letters in INDISTINGUISHABLE.**
+
+I–N–D–I–S–T–I–N–G–U–I–S–H–A–B–L–E (17 letters total):
+- I × 4, N × 2, S × 2, D × 1, T × 1, G × 1, U × 1, H × 1, A × 1, B × 1, L × 1, E × 1
+
+Total permutations = 17! / (4! · 2! · 2!)
+
+**Step 2: Define events and overlap analysis.**
+
+Let A = permutations containing "GIT", B = permutations containing "TIN", C = permutations containing "NAB".
+
+Key observations about overlaps (using letter multiplicities):
+- **T appears only once.** Both GIT and TIN require T, so if both appear, they must share T. The only overlap is GIT + TIN sharing T → **GITIN** (G–I–T–I–N).
+- **TIN ends with N; NAB starts with N.** They can share N → **TINAB** (T–I–N–A–B), or use separate N's (N appears twice).
+- **GIT and NAB share no letters**, so they always appear as separate blocks.
+
+**Step 3: Compute each term.**
+
+When treating a substring as a block, remove its letters from the pool and count permutations of (remaining letters + block) with appropriate repetition factors.
+
+**|A|:** GIT block. Remaining: I×3, N×2, S×2, others×1. Units = 15.
+|A| = 15! / (3! · 2! · 2!) = 54,486,432,000
+
+**|B|:** TIN block. Remaining: I×3, N×1, S×2, others×1. Units = 15.
+|B| = 15! / (3! · 2!) = 108,972,864,000
+
+**|C|:** NAB block. Remaining: I×4, N×1, S×2, others×1. Units = 15.
+|C| = 15! / (4! · 2!) = 27,243,216,000
+
+**|A ∩ B|:** GIT and TIN must overlap as GITIN (only one T). GITIN block uses G×1, I×2, T×1, N×1. Remaining: I×2, N×1, S×2, others×1. Units = 13.
+|A ∩ B| = 13! / (2! · 2!) = 1,556,755,200
+
+**|A ∩ C|:** GIT block + NAB block (no shared letters). Remaining: I×3, N×1, S×2, others×1. Units = 13.
+|A ∩ C| = 13! / (3! · 2!) = 518,918,400
+
+**|B ∩ C|:** Two sub-cases (both valid since N appears twice):
+- *Case 1 (overlap):* TINAB block (sharing N). Remaining: I×3, N×1, S×2, G×1, others×1. Units = 13. Count = 13! / (3! · 2!) = 518,918,400.
+- *Case 2 (non-overlap):* TIN block + NAB block (each using its own N). Remaining: I×3, S×2, G×1, others×1. Units = 13. Count = 13! / (3! · 2!) = 518,918,400.
+
+|B ∩ C| = 2 × 518,918,400 = 1,037,836,800
+
+**|A ∩ B ∩ C|:** GIT and TIN must form GITIN; then NAB can share or not share N with GITIN:
+- *Case 1 (overlap):* GITINAB block (G–I–T–I–N–A–B). Remaining: I×2, N×1, S×2, others×1. Units = 11. Count = 11! / (2! · 2!) = 9,979,200.
+- *Case 2 (non-overlap):* GITIN block + NAB block (using the remaining N). Remaining: I×2, S×2, others×1. Units = 11. Count = 11! / (2! · 2!) = 9,979,200.
+
+|A ∩ B ∩ C| = 2 × 9,979,200 = 19,958,400
+
+**Step 4: Apply inclusion-exclusion.**
+
+|A ∪ B ∪ C| = |A| + |B| + |C| − |A∩B| − |A∩C| − |B∩C| + |A∩B∩C|
+= 54,486,432,000 + 108,972,864,000 + 27,243,216,000
+ − 1,556,755,200 − 518,918,400 − 1,037,836,800
+ + 19,958,400
+= 190,702,512,000 − 3,113,510,400 + 19,958,400
+= 187,608,960,000
+
+Total permutations = 17! / (4! · 2! · 2!) = 3,705,077,376,000
+
+Answer = 3,705,077,376,000 − 187,608,960,000 = **3,517,468,416,000**
+
+---
+
+### Problem 3
+
+**Number of 1-1 functions f : {1, …, 20} → {1, …, 80} with no fixed point.**
+
+A fixed point is a ∈ {1, …, 20} with f(a) = a (only elements 1 through 20 can be fixed points, since a must lie in both the domain and the codomain for f(a) = a to hold, and the domain is {1,…,20}).
+
+**Total injective functions:** P(80, 20) = 80! / 60!
+
+**Apply inclusion-exclusion.** Let A_i = set of injective functions where f(i) = i.
+
+**|A_i|:** Fix f(i) = i; map remaining 19 domain elements injectively into 79 remaining codomain elements.
+|A_i| = P(79, 19) = 79! / 60!
+
+**|A_i ∩ A_j| (i ≠ j):** Fix f(i) = i and f(j) = j; remaining 18 elements map into 78 elements.
+|A_i ∩ A_j| = P(78, 18) = 78! / 60!
+
+**General k-fold intersection:** Fix f(i_1) = i_1, …, f(i_k) = i_k; remaining 20−k elements map into 80−k elements.
+|A_{i_1} ∩ … ∩ A_{i_k}| = P(80−k, 20−k) = (80−k)! / 60!
+
+By inclusion-exclusion, the number of injective functions with **at least one** fixed point is:
+
+sum_{k=1}^{20} (−1)^{k+1} · C(20, k) · (80−k)! / 60!
+
+Therefore, the number of injective functions with **no fixed point** is:
+
+sum_{k=0}^{20} (−1)^k · C(20, k) · P(80−k, 20−k)
+
+= sum_{k=0}^{20} (−1)^k · C(20, k) · (80−k)! / 60!
+
+Expanding:
+
+= P(80,20) − C(20,1)·P(79,19) + C(20,2)·P(78,18) − … + (−1)^{20}·C(20,20)·P(60,0)
+
+= (1/60!) · sum_{k=0}^{20} (−1)^k · C(20, k) · (80−k)!
Sub-Model Usage
| Model | Input | Output | Cache Read | Cost |
|---|---|---|---|---|
| claude-sonnet-4-6 | 6 | 35.9K | 166.8K | $1.29 |
BSCS Bench