# Nonnegative integer solutions to $2a+b=n$

I am trying to find number of solutions to $2a+b=n$ for $a,b\geq 0$ given some $n\geq 0$.

Anyone have ideas? Thanks!

You need $0\le 2a\le n$, so $0\le a\le \lfloor n/2\rfloor$, so your equation has $\lfloor n/2\rfloor+1$ solutions.

• Oh, that's easier than I thought. Thanks! – Ryan Stodola Jan 25 '17 at 18:34

First of all, we calculate the general solution of the homogenous equation $2a+b=0$.

It is $(t/-2t)$

A solution of $2a+b=n$ is $(0/n)$

Hence the general integer solution of $2a+b=n$ is $(t/n-2t)$

To make the solution non-negative , you have to choose $t$, such that $0\le t\le\frac{n}{2}$

So, the number of solutions is $1+\lfloor \frac{n}{2} \rfloor$