TITLE: Solving $x+2y+5z=100$ in nonnegative integers
QUESTION [7 upvotes]: I have not done combinatorics since high school, so this is an embarrassingly simple question.
We can solve the diophantine equation $x+y+z=100$ in nonnegative integers using the "bars and boxes" combinatorial method. We have $100$ dots, and we want place 2 partition markers among them, so the answer is ${ 102 \choose 2}$. Is there a way to generalize this (by a change of variable, perhaps) to equations like $x+2y+5z=100$? I know we can handle the case where we need to solve in positive integers by making the substitutions $x\rightarrow x+1$ and so forth, but I can't think of a way to apply a similar technique when the coefficients aren't $1$. 
If not, is there a slick way to handle these more general equations?

REPLY [8 votes]: We can also solve it without generating functions as follows.
First, as a lemma, what is the number of nonnegative solutions to $x + 2y = n$? For any choice of $y$ such that $0 \le 2y \le n$, we have a unique solution (take $x = n - 2y$), so the number of solutions is the number of such choices, i.e. $\lfloor \frac{n}{2} \rfloor + 1$ (or, if you like, $\lceil \frac{n+1}{2} \rceil$).
Now the number of solutions to $x + 2y + 5z = n$: for each choice of $z$ such that $0 \le 5z \le n$, the number of solutions is that of $x + 2y = n - 5z$. The total number of solutions is got by adding them up. 
For $n = 100$, the number $n - 5z$ takes values (enumerating the odd and even ones separately) $0, 10, \dots, 100$ and $5, 15, \dots, 95$, so the total number of solutions is 
$$\begin{align}
&\phantom{=} \left(\left\lceil \frac{0+1}{2} \right\rceil + \left\lceil \frac{10+1}{2} \right\rceil + \dots + \left\lceil \frac{100+1}{2} \right\rceil\right) + \left(\left\lceil \frac{5+1}{2} \right\rceil + \left\lceil \frac{15+1}{2} \right\rceil + \dots + \left\lceil \frac{95+1}{2} \right\rceil \right)\\
&= \left(1 + 6 + \dots + 51\right) + \left(3 + 8 + \dots + 48\right) \\
&= 286 + 255 = 541.
\end{align}$$