TITLE: How many natural solutions to $x_1+x_2+x_3+x_4=100$ with $x_1 \neq x_2 \neq x_3 \neq x_4$?
QUESTION [10 upvotes]: I have invented a little exercise of combinatorics that I can't solve (without brute forcing): in how many ways can I choose 4 non-negative integers, the sum of which is 100 and they are all different? So:
$x_1+x_2+x_3+x_4=100$
$x_1, x_2, x_3, x_4 \in \mathbb N$
$x_1 \neq x_2 \neq x_3 \neq x_4$
I have thought that the result have to be the number of total combination $\binom {100 + 4 - 1} {4 - 1}$ minus the ways I can solve $2x_1 + x_2 + x_3 = 100$. Anyway, I am not able to solve it either.
The solution should be:

 161664 or $\binom {100 + 4 - 1} {4 - 1} - 15187 = 176851 - 15187 = 161664$

Does anyone know how to calculate the combinations of this problem?

REPLY [2 votes]: Here is the solution from my side. One can translate this problem into a partition problem.
The much-studied partition function $p_k(n)$ is defined as the number of solutions of the equation $x_1+\cdots+x_k=n$ where $x_1\ge x_2\ge\cdots\ge x_k\ge1$; those solutions are called the partitions of $n$ into (exactly) $k$ parts. For fixed $k$, the generating function is
$$\sum_{k=0}^\infty p_k(n)x^n=\frac{x^k}{(1-x)(1-x^2)\cdots(1-x^k)}.$$
For $n\ge k\gt1$ we have the recurrence equation
$$p_k(n)=p_{k-1}(n-1)+p_k(n-k)$$
with initial values $p_0(0) = 1$ and $p_k(n) = 0$ if $n \le 0$ or $k \le 0$ , and $n$ and $k$ are not both zero
$x_1 + x_2 +x_3 +x_4 = 100$, where $x_i$ is non-negative integer.
Let, $x_1 = a_1$, $x_2 = x_1 + a_2$, $x_3 = x_2 + a_3$, $x_4 = x_3 + a_4$;
Where $a_1 \ge 0$ and $a_2, a_3, a_4 \ge 1$. This is to ensure that the numbers stay distinct
$4a_1 + 3a_2 + 2a_3 + a_4 = 100$
This is the exact same relation that appears when one resolves the equation of standard partition problem, except that $a_1$ should be $\ge 1$ and $a_2, a_3, a_4$ should be $\ge 0$.
We can do this by the following transformations
$a_1 = t_1 - 1$, $a_2 = t_2 + 1$, $a_3 = t_3 + 1$, $a_4 = t_4 + 1$
This satisfies our assumptions and now $t_1 \ge 1$ and $t_2, t_3, t_4 \ge 0$.
$4t_1 + 3t_2 + 2t_3 + t_4 = 98$
This is equivalent to dividing 98 into exactly 4 parts. Since all the 4 numbers can be aranged in any order to form other combinations of distinct non-negative $x_1, x_2, x_3, x_4$, therefore $4!$ should be multiplied.
The final answer would be $\Rightarrow 4! \cdot p_4(98)$
$p_4(98)$ can be calculated using the recurrence relation through hand or a computer program, but luckily we have closed form solutions available for certain values of $k$ in $p_k(n)$
$$p_4(n) = \left[ \frac{1}{144}t_4^3(n) - \frac{1}{48}t_4(n) \right]$$ for n is even
$$p_4(n) = \left[ \frac{1}{144}t_4^3(n) - \frac{1}{12}t_4(n) \right]$$ for n is odd
Here $\left[ \cdot \right]$ stands for nearest integer function and $t_k(n) = n + \frac{1}{4}.k(k-3)$
Subsitution values gives us $p_4(98) = \left[ \frac{99^3}{144} - \frac{99}{48} \right] = 6736$, $4! = 24$, $\Longrightarrow 24* 6736 = 161\:644$
A generalized approach for this problem has been disussed in this StackExchange question. This answer was also inspired by this answer