Formula for the $n$th term of $1, 2, 2, 3, 3, 3, 4, 4 ,4, 4, 5, ...$ There exists a formula for the $n$th term of this sequence A002024 from the OEIS ("$n$ appears $n$ times")
$$1, 2, 2, 3, 3, 3, 4, 4 ,4, 4, 5...$$
which is
$$\left \lfloor \frac {1+\sqrt{1+8n}}{2} \right \rfloor.$$
Is there a better formula for the $n$th term? A formula that isn't a 'magic' one that just happens to work but one that comes from a well-founded observation. Preferably one not using the floor function. I also have suspicions about the sustainability of the above formula as I feel with very $n$ it may not function properly. 
 A: You got nice answers already, so I'll just address the "sustainability" issue.
The formula you're discussing uses a real (non-integer) arithmetic to compute the integer solution of an integer problem. Theoretically, it is possible that at some point the square root is computed with a minor error and that the obtained solution is wrong (it may depend on processor, as well as some other factors).
To be absolutely certain that your program gives a correct solution (of course, as long as $n$ in the range of integers), you'll have to stick to the integer arithmetic. However, this means computing (but not remembering) the elements of your sequence, up to the $n$-th one. I don't think there is an integer-arithmetic formula that would save you from this.
A drawback? The speed, obviously, as such algorithm performs in $O(n)$ time, while the formula above computes in the constant time. This is significant, since the error should not occur for any reasonably small $n$.
All in all, I'd go with the above formula, as I'm fairly certain that this would not happen, since the square root would not allow lose $1$ as the significant digit, and I see no other threats, assuming that the processor is not buggy (i.e., it doesn't compute $\sqrt{x}$ to have a smaller integer part than the actual $\sqrt{x}$).
If it's absolutely crucial to get correct results for really large $n$, you might want to do some error estimate and see if the formula can actually produce wrong results. Again, I'm fairly certain that it can not.
A: I don't think there is a better formula, as it is based on two basic observations:


*

*$\displaystyle \sum_{k=0}^{m-1}k=\frac{m(m-1)}{2}$.

*$\displaystyle \frac{m(m-1)}{2}=n$ with $m>0$ $\Longrightarrow$ $\displaystyle m=\frac{1+\sqrt{1+8n}}{2}$.

Further explanations: 
We have a sequence $\{a_n\}$ such that $a_0=1$, $a_1=a_2=2$, $a_3=a_4=a_5=3$, etc, and we want to have a general formula for $a_n$. 
To obtain it, let us first ask a somewhat inverse question: for which $n$'s $a_n$ will be equal to a given number $m$? Here we will use the first formula: the numbers from $1$ to $m-1$ occupy $1+2+3+\ldots+(m-1)=m(m-1)/2$ first positions in the sequence. Therefore the number $m$ will  correspond to $m$ values of $n$ explicitly given by
$$n=\frac{m(m-1)}{2}+1,\frac{m(m-1)}{2}+2,\ldots,\frac{m(m-1)}{2}+m\tag{1}$$
Now we come back to our initial question. Given $n$, (1) implies that $a_n$ will be equal to the largest integer $m$ such that $\displaystyle \frac{m(m-1)}{2}\leq n$. This largest integer is obtained by solving the equation $\displaystyle\frac{m(m-1)}{2}= n$ for $m$ (here we use the 2nd formula) and taking the integer part of the solution.
A: There is a better formula: $$a_n = \operatorname{round}{\sqrt {2n}} $$
Where $\operatorname{round}$ means to round to the nearest integer, or if you prefer, $\operatorname{round}{x} = \left\lfloor x+\frac12\right\rfloor$
A: Let $a(n)$ denote the $n$th element of the sequence.
According to the OEIS,
$$\begin{cases}
a(1) &= 1\\
a(n) &= a(n - a(n - 1)) + 1.
\end{cases}$$
Proof of this formula. Two easy observations:
(1) If $\Delta$ is a triangular number, then $\Delta - a(\Delta)$ is the previous triangular number.
(2) If $\Delta'$ is a triangular number, $\Delta$ the previous triangular number and $n$ an integer such that $\Delta < n \leq \Delta'$, then
$$a(n) = a(\Delta') = a(\Delta + 1) = a(\Delta) + 1.$$
Let $n \geq 2$. Let $\Delta$ be the greatest triangular number such that $\Delta < n$ and $\Delta'$ the least triangular number such that $n \leq \Delta'$.
First case. $\Delta = n - 1$. Then
$$a(n) = a(\Delta + 1) \overset{(2)}{=} a(\Delta) + 1 \overset{(1),\,(2)}{=} a(\Delta - a(\Delta) + 1) + 1 = a(n - a(n-1)) + 1.$$
Second case. $\Delta \neq n - 1$. Then
(3) $\Delta < n-1 \leq \Delta'$ (follows from the def. of $\Delta$, $\Delta'$),
(4) $a(n) = a(n-1)$ (due to (2) and (3)).
Hence
$$\Delta - a(\Delta) \overset{(2)}{=} \Delta - (a(n) - 1) \overset{(3)}{<} n - 1 - (a(n) - 1) = n - a(n)$$
and
$$n - a(n) \overset{(2)}{=} n - a(\Delta') \leq \Delta' - a(\Delta') \overset{(1)}{=} \Delta$$
which combined give
$$\Delta - a(\Delta) < n - a(n) \leq \Delta.$$
This last line finally implies
$$a(n) \overset{(2)}{=} a(\Delta) + 1 \overset{(2)}{=} a(n - a(n)) + 1 \overset{(4)}{=} a(n - a(n - 1)) + 1.$$
