Counting Integer Solutions
On this page
Direct answer
Counting integer solutions means finding how many whole-number tuples satisfy a linear equation such as x + y + z = 10. The non-negative solutions of x₁ + ... + x_r = n number C(n + r − 1, r − 1), found by stars and bars: sharing 10 identical sweets among 3 children gives C(12, 2) = 66 ways. Upper caps are handled by subtracting violations through substitution and adding back double violations by inclusion–exclusion.
What you must remember
- Positive solutions: each xᵢ ≥ 1 gives C(n − 1, r − 1); x + y + z = 10 with all variables at least 1 has C(9, 2) = 36 solutions.
- Non-negative solutions: each xᵢ ≥ 0 gives C(n + r − 1, r − 1); x + y + z = 10 has C(12, 2) = 66.
- Lower bounds: substitute xᵢ = xᵢ′ + kᵢ and count non-negative solutions of the reduced equation.
- Upper bounds: count freely, then subtract the x ≥ m + 1 family, adding back overlaps when two caps can bind together.
- Generating-function view: the count is the coefficient of tⁿ in (1 − t)^(−r) without caps, or in (1 + t + ... + t^m)^r with caps m.
- Distinctness discipline: identical objects into distinct boxes use stars and bars; distinct objects need rⁿ when empty boxes are allowed, so the formulas are not interchangeable.
- Term-count link: the number of distinct terms of (x₁ + ... + x_k)^n is the non-negative count C(n + k − 1, k − 1).
Capping variables, step by step
A capped count starts from the free count and removes what breaks the cap. The worked case is x + y + z = 10 in non-negative integers with x ≤ 3 and y ≤ 3.
- Count the free solutions. Without caps, x + y + z = 10 has C(12, 2) = 66 non-negative solutions.
- Count the violations of x ≤ 3. Setting x = x′ + 4 gives x′ + y + z = 6, which has C(8, 2) = 28 solutions.
- Add the second cap. Capping y ≤ 3 as well gives another 28 violations, by symmetry.
- Count the double violations. Setting x = x′ + 4 and y = y′ + 4 gives x′ + y′ + z = 2, with C(4, 2) = 6 solutions.
- Assemble by inclusion–exclusion. The count is 66 − 28 − 28 + 6 = 16.
- Verify by a second route. The expansion (1 + t + t² + t³)² has coefficients 1, 2, 3, 4, 3, 2, 1, summing to 16, and each pair (x, y) fixes z = 10 − x − y ≥ 0.
Dropping the add-back in step 5 gives 10, a distractor value that setters place deliberately.
Where JEE sets its traps
Main usually asks the direct formula, while Advanced couples constraints or embeds the count in probability. Most errors come from three decisions made before any arithmetic.
- Trap: using C(n + r − 1, r − 1) for positive solutions. Correct: positive solutions need C(n − 1, r − 1), because each variable first takes one unit, leaving n − r units to distribute freely.
- Trap: dropping the add-back term when two caps can bind together. Correct: inclusion–exclusion adds the double violations back, so x ≤ 3 with y ≤ 3 gives 16, not 10.
- Trap: treating the variables as unlabelled, so solutions are counted up to permutation. Correct: stars and bars counts labelled variables; solutions up to permutation are integer partitions, which have no stars-and-bars formula.
Frequently asked questions
How many positive solutions does x + y + z = 10 have?
C(9, 2) = 36 positive integer solutions. Each variable must be at least 1, so stars and bars places 2 dividers in the 9 gaps between the 10 units.
How do I count solutions with an upper bound like x ≤ 3?
Count all non-negative solutions first, then subtract those with x ≥ 4 using the substitution x = x′ + 4. If a second cap can also be violated, add back the double violations, as inclusion–exclusion requires.
What is the generating-function link to these counts?
The number of non-negative solutions of x₁ + ... + x_r = n is the coefficient of tⁿ in (1 − t)^(−r). Imposing a cap of m on each variable replaces this series with (1 + t + ... + t^m)^r.
Do the variables need to be ordered?
Yes. Stars and bars counts labelled variables, so (x, y, z) and (y, x, z) are counted as separate solutions when x and y differ. Counting up to permutation is the integer partition problem, which needs different tools.
How does this connect to multinomial expansions?
The number of distinct terms of (x₁ + ... + x_k)^n equals C(n + k − 1, k − 1), the non-negative solution count for exponents summing to n. Each term is fixed by its exponent tuple, so the two counts match.