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.

  • 1
    $\begingroup$ Funny that the answer to this question isn't really related to the original statement. $\endgroup$ Commented Dec 3, 2016 at 19:30
  • $\begingroup$ you may not always get an integer value for n. You get an integer value only when m itself is a triangular number ( google triangular number). $\endgroup$
    – user25406
    Commented Dec 3, 2016 at 22:40
  • $\begingroup$ @SimpleArt: actually it sort of did, it did say "Get n from formula..." Anyway I clarified the OP's title now. $\endgroup$
    – smci
    Commented Dec 4, 2016 at 12:15
  • 1
    $\begingroup$ If you are doing this in, say, C: uint64_t n = sqrt(2.0 * m); for small enough values of m. $\endgroup$ Commented Dec 4, 2016 at 14:36
  • 5
    $\begingroup$ Duplicate: Gauss Sums: Reversing the $T(n) = \frac{n(n+1)}{2}$ formula. (Found using Approach0.xyz) $\endgroup$
    – Workaholic
    Commented Dec 4, 2016 at 19:18

3 Answers 3


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).

  • 1
    $\begingroup$ I downvoted before you edited to include the quadratic equation. Your first paragraph (i.e., "just look for two consecutive integers whose product is $2m$) is little more than a restatement of the problem. I removed the downvoted when you added the second paragraph. $\endgroup$
    – Théophile
    Commented Dec 3, 2016 at 17:07

Not the answer you're looking for? Browse other questions tagged .