---
title: "Bounded Non-Negative Integer Solutions via Inclusion-Exclusion"
organization: "NityaDhi Digital Mathematics Lab (Asa Edtech Private Limited)"
url: "https://www.nityadhi.com/problems/hard-c11-w1-16-bounded-integer-solutions-pie"
board: "JEE Foundation"
grade: "Class 11"
published_at: "2026-11-29T09:45:00+05:30"
---

# Bounded Non-Negative Integer Solutions via Inclusion-Exclusion

Find the number of integer solutions $(x_1, x_2, x_3, x_4)$ to the equation
$$x_1 + x_2 + x_3 + x_4 = 18$$
satisfying the constraints $1 \le x_1 \le 5$, $2 \le x_2 \le 6$, $x_3 \ge 0$, and $x_4 \ge 3$.

## Textbook Solution

First, absorb all lower bounds by defining shifted non-negative variables:
$$y_1 = x_1 - 1,\quad y_2 = x_2 - 2,\quad y_3 = x_3,\quad y_4 = x_4 - 3$$
The constraints translate into:
$$y_1 + y_2 + y_3 + y_4 = 18 - (1 + 2 + 0 + 3) = 12$$
with $0 \le y_1 \le 4$, $0 \le y_2 \le 4$, $y_3 \ge 0$, and $y_4 \ge 0$.
Now apply the Principle of Inclusion-Exclusion (PIE) to handle the upper bounds $y_1 \le 4$ and $y_2 \le 4$:
- **Total non-negative solutions (no upper bounds):**
  $$\binom{12 + 4 - 1}{4 - 1} = \binom{15}{3} = \frac{15 \times 14 \times 13}{6} = 455$$
- **Solutions violating $y_1 \le 4$ (so $y_1 \ge 5$):** Let $y_1' = y_1 - 5 \ge 0$, giving sum $12 - 5 = 7$:
  $$\binom{7 + 3}{3} = \binom{10}{3} = \frac{10 \times 9 \times 8}{6} = 120$$
- **Solutions violating $y_2 \le 4$ (so $y_2 \ge 5$):** By symmetry, also $\binom{10}{3} = 120$.
- **Solutions violating BOTH $y_1 \ge 5$ and $y_2 \ge 5$:** Let $y_1' = y_1 - 5 \ge 0$ and $y_2' = y_2 - 5 \ge 0$, giving sum $12 - 10 = 2$:
  $$\binom{2 + 3}{3} = \binom{5}{3} = 10$$

By Inclusion-Exclusion:
$$\text{Valid solutions} = 455 - 120 - 120 + 10 = 225$$

## Vedic Shortcut

**NityaDhi Generating-Function Coefficient Trick:** Write the exact generating function for $(y_1, y_2, y_3, y_4)$:
$$[x^{12}]\, (1 + x + \dots + x^4)^2 (1 - x)^{-2} = [x^{12}]\, (1 - x^5)^2 (1 - x)^{-4}$$
Expand $(1 - x^5)^2 = 1 - 2x^5 + x^{10}$ and use $[x^n](1 - x)^{-4} = \binom{n+3}{3}$:
$$\binom{15}{3} - 2\binom{10}{3} + \binom{5}{3} = 455 - 240 + 10 = 225$$
This algebraic template prevents missing any intersection terms!

## Common Mistakes

1. **Forgetting to add back the double-violation intersection:** Computing $455 - 120 - 120 = 215$ misses the $+10$ cases where both $y_1 \ge 5$ and $y_2 \ge 5$ were subtracted twice.
2. **Shifting upper bounds wrongly:** Setting $y_1 \le 5$ instead of $y_1 = x_1 - 1 \le 4$ shifts the exclusion threshold from $5$ to $6$.