How many ways can a number be written as a sum of two non negative integers?

1.3k Views Asked by At

How many ways can a number be written as a sum of two non negative integers?

For example there is $4$ way for $7$. $ 7=0+7=1+6=2+5=3+4$

I think there is $[ \frac{N}{2}]+1$ way for number$N$. Is it true?

1

There are 1 best solutions below

3
On BEST ANSWER

If you consider 3+4 and 4+3 as two different ways then yes it will be N+1. Think of it as placing a partition in a row of N objects you can place it right in the beginning, right at the end and any of the N-1 locations. However if 3+4 and 4+3 are considered same then we have only 4 ways of writing 7 as sum of two numbers. In this case the answer will be ceil((N+1)/2) where ceil(x) is smallest integer greater is Han or equal to x.