# General term of a sequence.

So i have the following sequence:

${1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, ...}$

Where the number $i$ appears $i + 1$ times.

I would like to know the $n$-th term of this sequence. I tried to analise certain patterns within the sequence, but wasn´t able to conclude anything so far.

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$.

• +1 Nice piece of work. Commented Jun 1, 2018 at 13:28
• Thank you, I spent an hour making this just to know that the first answer was accepted before. Commented Jun 1, 2018 at 13:34
• A shame. I am slow to accept answers for this reason. Commented Jun 1, 2018 at 15:51

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$

$n \in \mathbb{N}$ appears $n+1$ times starting from the position $$1 + \sum_{i=1}^{n-1}(i+1) = n + \frac{n(n+1)}2 = \frac12n(n+3)$$

Therefore, $$a_n = k \iff n \in \left[\frac12k(k+3), k+\frac12k(k+3)\right]$$

so $k$ is the smallest integer with $n \ge \frac12k(k+3)$.

Solving this for $k$, we obtain $$a_n = \left\lceil\frac{-3+\sqrt{9+8n}}2\right\rceil, \quad n\in \mathbb{N}$$

Given $\color{red}1, 1, \color{red}2, 2, 2, \color{red}3, 3, 3, 3, \color{red}4, 4, 4, 4, 4, \color{red}5, ...$, first note that: $a_{T(k)}=k$, where $T(k)$ is a triangular number. Indeed: $$a_{T(1)}=a_1=\color{red}1; a_{T(2)}=a_3=\color{red}2; a_{T(3)}=a_6=\color{red}3; a_{T(4)}=a_{10}=\color{red}4; a_{T(5)}=a_{15}=\color{red}5; \ ...$$ Hence: $$T(k)\le n\le T(k+1)-1, a_n=k \iff \\ \frac{k(k+1)}{2}\le n\le \frac{(k+1)(k+2)}{2}-1 \iff \\ k^2+k-2n\le 0\le k^2+3k-2n \iff \\ \left\lceil \frac{\sqrt{8n+9}-3}{2}\right\rceil\le k\le \left\lfloor \frac{\sqrt{8n+1}-1}{2}\right\rfloor$$ Hence: $$a_n=\left\lceil \frac{\sqrt{8n+9}-3}{2}\right\rceil \ \text{or} \ \left\lfloor \frac{\sqrt{8n+1}-1}{2}\right\rfloor.$$