How to get inverse of formula for sum of integers from 1 to n? [duplicate]

I know very well that the sum of integers from $1$ to $n$ is $\dfrac{n\times(n+1)}2$. What I'm interested in today, and cannot find a solution for, is performing the opposite operation.

Let $m = \dfrac{n^2 + n} 2$. Knowing the value of $m$, how do I figure out the value of $n$? I could easily program a solution but I'd much prefer an algebraic one.


Simple algebra suffices: $$\begin{align} m &= \frac{n^2+n}{2} \\ 2m &= \left(n+\frac{1}{2}\right)^2 - \frac{1}{4} \\ \sqrt{2m + \frac{1}{4}} - \frac{1}{2}&= n \end{align} $$

and we are done.


The easiest and quickest way is to multiply $m$ by $2$, take the square root, and round that down to the nearest whole number.

For Example: $m = 55$. And, $55*2 =110$. We have $\sqrt{110} = 10.4$.... Round down to $10$. So, $n=10$

This works because we know $2m = n\times (n+1)$, so square root of that is between $n$ and $n+1$.

But if you want an algebraic solution, you can use the formula $n = \frac{-1+\sqrt{1+8\times m}}{2}$

Same example: $m=55:$ $n= \frac{-1+\sqrt{1+8\times55}}{2} = \frac{-1+\sqrt{441}}{2} = \frac{-1+21}{2} = \frac{20}{2} =10$


You have got that $m = \dfrac{n^2 + n} 2$ which will give you $2m=n(n+1)$.

You can make a quadratic equation $n^2+n-2m=0$. On solving the quadratic equation you get that $n=\frac{-1 \pm\sqrt{1+8m}}{2}$. Now solve this (as you know the $m$, you can easily find $n$) and eliminate the negative solution (As $n$ can not be negative).