4

A triangular number is a number that is the sum of the natural numbers up to some $n$. The closed form is $x = \frac{n(n+1)}{2}$. How do I get $n$ on one side? I've been looking at it from every angle, and I can't find out how. Any help?

Sawarnik
  • 7,404
undo_all
  • 255

2 Answers2

9

The answer elsewhere in this thread is of course correct, but for actual calculation there is a simpler answer. We have $x = \frac12(n^2 +n)$ where $x$ is known and we want to find $n$. This is equivalent to $$2x+\frac14 = \left(n+\frac12\right)^2$$ or, neglecting the fractions, which I could justify with a more careful analysis, but won't, $$n\approx \sqrt{2x}.$$

And indeed the formula $$n = \left\lfloor\sqrt{2x}\right\rfloor$$ always gives the correct answer. ($\lfloor\ldots\rfloor$ just means to drop the fraction.)

MJD
  • 67,568
  • 43
  • 308
  • 617
  • 1
    You might want to prove that it always gives the correct answer. Nice trick though :) – Sawarnik Mar 04 '14 at 19:42
  • I thought it might be more fun if I left it as an exercise. – MJD Mar 05 '14 at 02:23
  • You might want to check the answer by substituting it back in the original formula though, since this is going to give an integer always. Nice trick +1. :) – Guy Mar 05 '14 at 09:26
  • 1
    Very nice trick. A funny way to think about it: if $x$ is the area of an equilateral triangle, $2x$ is the area of a rhombus and $\sqrt{2x}$, its side. – schneiderfelipe Jan 15 '21 at 22:33
8

$$n^2+n=2x$$

$$n^2 +n - 2x = 0$$

$$n = \frac{-1 +\sqrt{1+8x}}{2}\text{ provided $n \in \mathbb N,$ otherwise undefined}$$


For anyone unfamiliar, see proof.

Guy
  • 9,055
  • 1
  • 30
  • 58