What is the $n$th term of the sequence $1, 1, 4, 1, 4, 9, 1, 4, 9, 16, 1 ...$ So there exist a lot of similar questions which ask the $n$th term of  
$$1^2 , (1^2 + 2^2) , (1^2 + 2^2 + 3^2) ... $$
Which have a simple answer as
$$T_n = n^3/3 + n^2/2 + n/6$$
But I want to know what will be the $n$th term if we consider each number as a single term. I tried making a pyramid of terms and got this
$1^2\\
1^2~2^2\\
1^2~2^2~3^2\\
1^2~2^2~3^2~4^2\\
...$
I got the $n$th term as$$T_n= (n\mod(m(m-1)/2)^2$$
Where $m$ is the row number.

But now I am stuck, is there a way to eliminate $m$ and write the general term only in terms of $n$?


The number of terms in $x$ rows is $1+2+...+x=x(x+1)/2$. The row number $m$ of $n^{\text{th}}$ term is thus the smallest positive integer solution of $x(x+1)/2\ge n$. The roots of $x^2+x-2n=0$ are $\frac{-1\pm\sqrt{8n+1}}2$. First, we reject the negative root. Next, we take the ceiling value of the positive root as it may not be a whole number.
Thus,$$m=\left\lceil\frac{-1+\sqrt{8n+1}}2\right\rceil$$

As a side note, you can ditch the mod and use regular subtraction in your formula.
