Find number of non negative integral solutions to this equation $$a+b+c+d=24$$ such that $a⩽b⩽c⩽d$.


closed as off-topic by Servaes, Martin Argerami, Abcd, Eevee Trainer, mrtaurho Apr 1 at 6:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is missing context or other details: Please provide additional context, which ideally explains why the question is relevant to you and our community. Some forms of context include: background and motivation, relevant definitions, source, possible strategies, your current progress, why the question is interesting or important, etc." – Servaes, Martin Argerami, Abcd, Eevee Trainer, mrtaurho
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Your question is phrased as an isolated problem, without any further information or context. This does not match many users' quality standards, so it may attract downvotes, or be put on hold. To prevent that, please edit the question. This will help you recognise and resolve the issues. Concretely: please provide context, and include your work and thoughts on the problem. These changes can help in formulating more appropriate answers. $\endgroup$ – R_B Mar 31 at 15:03
  • $\begingroup$ Welcome to MathSE. Please edit your question to show what you have attempted and explain where you are stuck so that you receive responses that address the specific difficulties you are encountering. This tutorial explains how to typeset mathematics on this site. $\endgroup$ – N. F. Taussig Mar 31 at 15:38
  • $\begingroup$ @N.F Taussing thank you sir,can you help me with that question $\endgroup$ – Raviraz Mar 31 at 15:40
  • $\begingroup$ Hint If you start with $d$ as large as possible and work downward, it will be pretty easy to build a list of these partitions without duplicates. $\endgroup$ – hardmath Mar 31 at 16:26

Suppose that you want to solve the equation:


assuming that the minimum allowed value of $a_i$ is $m$ and $a_i\ge a_j$ if $i\ge j$. Denote the number of solutions of such equation as $f(n, m, s)$. Basically, you want to find $f(4, 0, 24)$ because you have 4 variables, these variables are greater or equal to zero and the total sum is 24.


$m\gt s\implies f(n, m, s)=0\tag{1}$

...which basically means that there is no solution if the minimum value of $a_i$ is greater than total $s$. Also we have:

$$n=1\land m\le s\implies f(n,m,s)=1\tag{2}$$

In other words, if you have only one variable and if the minimum allowed value is smaller than the total sum, there is exactly one solution.

And finally:

$$f(n,m,s)=\sum_{m'=m}^s f(n-1,m',s-m')\tag{3}$$

This simply means that you can pick the value of the first variable anywhere between the minimum allowed value $m$ and the total sum $s$ and find a number of solutions for the smaller sum with one variable less. When you sum all those solutions you get the final result.

Rules (1), (2) and (3) are sufficent to calculate the number of solutions for any $n,m,s$

You can represent these three rules in Mathematica in the following way:

f[length_, minimum_, total_] := 0 /; minimum > total

f[1, minimum_, total_] := 1  /; minimum <= total

f[length_, minimum_, total_] := Sum[f[length - 1, k, total - k], {k, minimum, total}]


f[4, 0, 24]

...returns 169.

The number of solutions grows fairly quickly. If you replace $s=24$ with $100$ the result is 8037.

  • $\begingroup$ Thanks you @oldboy.. $\endgroup$ – Raviraz Mar 31 at 20:51

The number you are looking for, is known as partition function of a number $n$ into $k$ non-negative parts (in your case $n=24$, $k=4$).

It can be computed as $$ p_k(n+k), $$ where $p_k(n)$ is the partition function of a number $n$ into $k$ positive parts.

Though no closed-form expression for $p_k(n)$ exists, it can be easily computed by the recurrence relation: $$ p_k(n) = p_k(n − k) + p_{k−1}(n − 1), $$ with initial values $p_k(n) = 0$, if $n ≤ 0$ or $k ≤ 0$, except for $p_0(0) = 1$.

In your case the result reads: $$ p_4(28)=169. $$


Not the answer you're looking for? Browse other questions tagged or ask your own question.