0
$\begingroup$

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!

2 Answers 2

1

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.

  • 0
    Oh, that's easier than I thought. Thanks!2017-01-25
0

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$