# Given $x$, find $n$ such that $1 + 2 + 3 + ... n = x$ [closed]

Given a number $x$, how do we find a value $n$ such that $$1+2+3+...+n =x$$ This is how far I've gotten: $$x=\frac{n(n+1)}{2}$$ $$2x = n(n+1)$$ What do I do from here???

– lulu
Mar 23, 2018 at 11:43
• @lulu Oh....... Mar 23, 2018 at 11:45

Then we will have $n^2+n-2x=0$

You can find solution for $n$ if and only if $x$ is a natural number and $\Delta=1^2-4\times 1 \times (-2x)=8x+1\ge0$, which is true for all nautral numbers $x$.

Then we will have $n=\frac{-1+\sqrt{8x+1}}{2}$ or $n=\frac{-1-\sqrt{8x+1}}{2}$, but we will only take the positive integer solution, eliminate any non-integer solution.

Note that $8x+1$ must be a perfect square number so that $n$ can be a positive integer.

• Note that $8x+1$, if a square, is always going to be odd, so specifying that isn't necessary.
– user304329
Mar 23, 2018 at 11:59
• So $n=\max(\frac{-1+\sqrt{8x+1}}{2}, \frac{-1-\sqrt{8x+1}}{2})$? Mar 23, 2018 at 12:00
• Note that $8x+1$ will always be odd, so the only condition is that it is a square. Mar 23, 2018 at 12:00
• @user5011: Well, yes, but it's simpler just to say $n=\frac{-1+\sqrt{8x+1}}2.$ Mar 23, 2018 at 12:01
• Okay, got it now. Thanks a lot!$n = \frac{-1+\sqrt{8x+1}}{2}$. Mar 23, 2018 at 12:02

You need to solve $$n^2+n-2x =0$$

As you know this quadratic equation may or may not have integer solutions.

For example $x=55$ results in $n=10$ but $x=50$ does not have a round solution.