General term of a sequence.

I would like to put a "number pyramid" like this:

$$1-1$$

$$2-2-2$$

$$3-3-3-3$$

$$4-4-4-4-4$$

$$5-5-5-5-5-5$$

$$\cdots$$

$$k-\text{th floor: } k-k-k-k-k-...-k-k\text{ ($k+1$ times)}$$

The number of numbers appear in all the floors from $1$ to $k-1$:

$$2+3+4+5+\cdots+k=\dfrac{(k+2)(k-1)}{2}$$

The number of numbers appear in all the floors from $1$ to $k$:

$$2+3+4+5+\cdots+k+k+1=\dfrac{(k+3)k}{2}$$

Assume that the $n$-th term of the sequence above is on the $k$-th floor (the bottom floor of the pyramid above), then $n$ may or may not be the last term of the $k$-th floor, so this inequality must hold (we need to find $k\in\mathbb{Z^+}$ given $n\in\mathbb{Z^+}$):

$\dfrac{(k+2)(k-1)}{2}<n\le\dfrac{(k+3)k}{2}$

$\Leftrightarrow k^2+k-2<2n\le k^2+3k$

$\Leftrightarrow \begin{cases}k^2+k-2n-2<0\\k^2+3k-2n\ge 0\end{cases}$

$$k^2+k-2n-2<0$$

$\Leftrightarrow k^2+2\times k\times 0.5+0.25-2n-2.25<0$

$\Leftrightarrow (k+0.5)^2<2n+2.25$

$\Leftrightarrow k+0.5<\sqrt{2n+2.25}$ (because $k,n>0$)

$\Leftrightarrow k<-0.5+\sqrt{2n+2.25}$

$\Leftrightarrow k<\dfrac{-1+\sqrt{8n+9}}{2}$

$$k^2+3k-2n\ge 0$$

$\Leftrightarrow (k+1.5)^2\ge 2n+2.25$ (similar to above)

$\Leftrightarrow k+1.5\ge \sqrt{2n+2.25}$ (because $k,n>0$)

$\Leftrightarrow k\ge \dfrac{-3+\sqrt{8n+9}}{2}$

Combine both equations, we have

$$\dfrac{-3+\sqrt{8n+9}}{2}\le k<\dfrac{-1+\sqrt{8n+9}}{2}$$

Other notes:

  • The conclusion above is still true for $n\in\mathbb\{1;2\}$ and $k=1$. When $k=1$, the number of numbers appear in all the floors from $1$ to $0$ is zero (no numbers exist), because when $k=1$ we have $\dfrac{(k+2)(k-1)}{2}=0$.

  • There is always exactly one positive integer $k$ satisfy the conclusion above (for all $n\in\mathbb{Z^+}$), because the difference between the right hand side and the left hand side is $1$.


According to OEIS the general formula is $$ a(n) = \lfloor (\sqrt{1+8n}-1)/2\rfloor. $$


If $t_n$ denotes the value of the $n$-th term then:

$$2+3+\cdots+t_n<n\leq2+3+\cdots+t_n+(t_n+1)=\frac12t_n(t_n+3)$$

so that $t_n$ is the smallest integer that satisfies: $$2n\leq t_n(t_n+3)$$leading to $t_n=\lceil\frac12\sqrt{9+8n}-\frac32\rceil$