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!

$\endgroup$
1
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Oh, that's easier than I thought. Thanks! $\endgroup$ – Ryan Stodola Jan 25 '17 at 18:34
0
$\begingroup$

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$

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.