6

Can someone reverse this formula? Sorry if it's too basic, I'm an old guy and my math is rusty :-D

$s =\frac{n(n+1)}{2}$

If it ain't clear, by reverse I mean obtaining the value of n by providing s

Thanks

Milad.N
  • 171

1 Answers1

9

$$s= \frac{n^2+n}{2}$$ $$n^2+n-2s=0$$ This is a degree two polynomial equation in the variable $n$, whose positive solution is $$n= \frac{-1 + \sqrt{1+8s}}{2}$$

Crostul
  • 36,738
  • 4
  • 36
  • 72
  • well, i sure as hell don't remember a polynomial equation :-(. Thanks a lot :-) – Milad.N May 09 '16 at 18:48
  • 1
    The equation $ax^2+bx+c=0$ has two solutions, namely $$\frac{-b \pm \sqrt{b^2-4ac}}{2a}$$ Never seen this formula? – Crostul May 09 '16 at 18:49
  • 2
    See https://en.wikipedia.org/wiki/Quadratic_equation – Crostul May 09 '16 at 18:50
  • Of course I have :-). I've just been away from math for a very long time. I knew it had to be something like that. At first I though it was (a + b)^2, but then I remembered the sign of n is wrong. – Milad.N May 09 '16 at 18:51
  • And guess what, I wanted to use it in an algorithm of some sort, but now I realised that it won't yield the result I need. Such a shame. At least I ~remembered~ re-learned some of the good stuff. – Milad.N May 09 '16 at 18:55
  • It’s perhaps worthwhile to note that if you know that $n$ is a non-negative integer, you can compute it as $\left\lfloor\sqrt{2s}\right\rfloor$. – joriki Mar 13 '24 at 15:00