Integer solutions to an equation with a constant before x The question is:
How many integer solutions are there to the equation
$$x_1 + x_2 + x_3 + x_4 + 3x_5 = 80$$
if $x_i$ is greater than or equal to 0?
I understand how to get integer solutions to a regular equation. But the constant before $x_5$ threw me off. Would you divide the answer by $3$? 
My solution was $C(80+5-1, 80)/3$. I think that's wrong
 A: Let $A(n,k)$ be the way to write $n$ as a sum of $k$ nonnegative integers, the last of which must be divisible by $3$. The number we're looking for is then $A(80,5)$.
As a base case, it is clear that
$$A(n,2)=\lfloor n/3\rfloor+1$$
When $k>2$, imagine writing down all ways to write $n$ as a sum of $k$ numbers with no further restrictions. This can be done in $\binom{n+k-1}{n}$ ways.
For each of the sums where the last term is not divisible by $3$, subtract $1$ or $2$ from it, and add them instead to the first term. In this way each solution arises three times, except the ones with $x_1=0$ (which arise only once) and the ones with $x_1=1$ (which arise twice each).
The number of solutions with $x_1=0$ is $A(n,k-1)$; the number of solutions with $x_1=1$ is $A(n-1,k-1)$. Thus, by keeping track of the overcounting we have
$$ A(n,k) = \frac13\biggl[\binom{n+k-1}{n} + 2A(n,k-1) + A(n-1,k-1)\biggr] $$
With this recurrence, you can compute $A(80,5)$ by dynamic programming just by computing
$$ \begin{matrix} A(77,2) & A(78,2) & A(79,2) & A(80,2) \\ & A(78,3) & A(79,3) & A(80,3) \\ && A(79,4) & A(80,4) \\ &&& A(80,5) \end{matrix} $$
which requires fewer binomial coefficients than it would take to compute the number of solutions separately for the last term being $0,3,6,9,\ldots,78$.
A: Here there is a Visual Basic programm to be run in Excel:
Sub Macro1498995()
'
' Macro1498995
'
CONT = 1

For X1 = 0 To 80
For X2 = 0 To 80
For X3 = 0 To 80
For X4 = 0 To 80
For X5 = 0 To 27

Sum = X1 + X2 + X3 + X4 + 3 * X5

If Sum = 80 Then
    Cells(CONT, 1) = X1
    Cells(CONT, 2) = X2
    Cells(CONT, 3) = X3
    Cells(CONT, 4) = X4
    Cells(CONT, 5) = X5
    CONT = CONT + 1
End If

Next X5
Next X4
Next X3
Next X2
Next X1
'
End Sub

According to this, we have 674541 possibilities.
