11

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.

smci
  • 364
SolarBear
  • 221

3 Answers3

25

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.

Rory Daulton
  • 32,288
22

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$

Bram28
  • 100,612
  • 6
  • 70
  • 118
11

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
    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. – Théophile Dec 03 '16 at 17:07