0
$\begingroup$

I'm building an algorithm to determine whether a value is inside a series. To speed it up, I need the inverse function of the following series:

$1 + 2 + 3+\cdots +n$

What is the inverse function of $f(n) = \frac{n(n + 1)}{2}$?

3 Answers 3

4

I don't understand much of your question, but if $f(n)={n(n+1)\over2}$ then $8f(n)+1=(2n+1)^2$ so $n={\sqrt{8f(n)+1}-1\over2}$

  • 0
    Thank you for clarifying! I really appreciate it.2012-06-29
2

$ f(n)={n(n+1)\over2}$ $\implies 2 f(n) = n^2+n$ $\implies 2f(n) +\frac 14 = (n)^2 + 2\times n\times \frac 1 2 +\left(\frac 12\right)^2 $

$\implies 2f(n)+\frac 1 4 = \left(n+\frac 12 \right)^2 $ $\implies n = \sqrt{2 f(n)+\frac{1}{4}} -\frac{1}{2}$

$ \implies n = \frac{\sqrt{8 f(n)+1}}{2} -\frac{1}{2}$

which gives the expression @Gerry Myerson posted.

0

Inverse of given function is $\frac{\sqrt{8f(n)+1}-1}2$(as solved by @Gerry Myerson),but this function is helpful only if the series you are considering is first $n$ natural numbers(in that case, every integer $\geq 1$ and $\leq$ number provided by this inverse function is in the series).