# Total number of integer solutions with constraints

Find the number of ways 5 dices can be rolled to get a sum of 25.

While solving this question, the way we solve it is $$x_1+x_2+x_3+x_4+x_5$$ $$=25$$ where $$1<=x_i<=6$$

So we replace $$x_i$$ by $$y_i =6-x_i$$ , which is $$x_i=6-y_i$$

substituting $$x_i$$ in the above equation we get it as→ $$(6*5) – (y_1+y_2+y_3+y_4+y_5)$$ $$=25$$

$$(y_1+y_2+y_3+y_4+y_5)$$ = $$5$$

After solving this equation by integer solutions formula $$(n-r+1)! / (n! * (r-1)!)$$ we get the ans as → $$126$$

Now consider this problem,

The number of non-negative integer solutions such that $$x_1+x_2+x_3=17$$ where $$x_1>1, x_2>2 , x_3>3$$ is ___________________

While solving this we are solving it like → $$y_1= x_1-2$$ , $$y_2=x_2 -3$$ , $$y_3=x_3-4$$

so, $$x_1= y_1+2$$ , $$x_2=y_2 +3$$ , $$x_3=y_3+4$$

Now we substitute this in our original equation to get→

$$y_1+2+y_2 +3+y_3+4 =17$$

$$y_1+y_2 +y_3 =8$$

and after solving this we get the ans as $$45$$

Now I have a $$DOUBT$$ here, in the second problem since when $$x_1>1$$ we make it as $$x_1 = y_1+2$$ , but in the first problem all the dices should have value $$>0$$ , so why in that case we haven’t made $$x_i=y_i+1$$ for all the cases?

And moreover what if the question was like

$$x_1+x_2+x_3=12$$   ,  $$2<=x<=5$$ then how to solve this using integer solution and applying the formula $$(n-r+1)! / (n! * (r-1)!)$$ ?

• In the first case, it's a way to incorporate the constraint that each die is at most 6. The right hand side you end up with is 5 which is less than 6 – ogogmad Oct 19 '19 at 18:28
• In your third case, I would write $y_i = 3 + x_i$, use the formula, and then take away 3 solutions – ogogmad Oct 19 '19 at 18:29
• Alternatively, in the third case you could write $x_i = 5 - y_i$, simplify to $y_1 + y_2 + y_3 = 3$, and then observe that you don't have to take away solutions – ogogmad Oct 19 '19 at 18:31
• In my first example, I meant to use $2$ not $3$. – ogogmad Oct 19 '19 at 18:33

We have a lot of freedom in how to solve the third problem.

We could substitute $$x_i = 2 + y_i$$, use the formula, and then take away three solutions. Those three solutions correspond to $$(6,0,0), (0,6,0)$$ and $$(0,0,6)$$, which violates the constraint that $$x \leq 5$$.

Alternativrly, we could substitute $$x_i = 5 - y_i$$, simplify the equation to $$y_1 + y_2 + y_3 = 3$$, and then use the counting formula. Observe that we don't need to take away solutions, because the constraint that $$2<=x<=5$$ is automatically satisfied. This is slightly more convenient.

So the second approach is marginally better in that it doesn't require taking away solutions. But the advantage either way is negligible.

• Thanks for your explanation, couldn't upvote because of low points.. – Turing101 Oct 19 '19 at 19:13
• Moreover I have a doubt here, say if the equation was $x_1+x_2+x_3=12$ , $1<=x<=5$, then what should have been our approach as $x_i=5-y_i$ would give the same result here also, but which is not the case, here we should have more number of solutions – Turing101 Oct 19 '19 at 19:14
• None of $x_1$, $x_2$ or $x_3$ can be $1$, as then the sum is always less than 12. So the number of solutions does indeed stay the same – ogogmad Oct 19 '19 at 19:27
• okay, and if it was like $x1+x2+x3=12 , 3<=x<=5$, then what? aren't there any generalized formulas for these problems? – Turing101 Oct 20 '19 at 3:56
• If $3 \leq x \leq 5$ then you have to take away solutions. There's no general formula – ogogmad Oct 20 '19 at 4:04