# Largest Triangular Number less than a Given Natural Number

I want to determine the closest Triangular number a particular natural number is. For example, the first 10 triangular numbers are $1,3,6,10,15,21,28,36,45,55$ and thus, the number $57$ can be written as $$57=T_{10}+2$$ The number $54$ can be written as $$54=T_{9}+9\neq T_{10}-1$$ The second part highlights that I am looking for Triangular numbers larger than a particular positive, and not necessarily "closer" in terms of distance from Triangular numbers.

My approach would be this; given the $n$-th Triangular number has the formula $$T_n=\frac{n(n+1)}{2}=\binom{n+1}{2}$$ If I'm looking for a particular breakdown and close Triangular number, my number, say, $M$ will be of the form $$M=T_k+r$$ where $0\le r\le k$, and thus $$2(M-r)=k^2+k$$ And thus $$k=\frac{-1\pm\sqrt{1+8(M-r)}}{2}$$ I'm lost here in trying to solve, given that $r$ varies. I know that $r$ is less than or equal to $k$ but for sufficiently large $M$, how would I go about finishing solving?

$\binom{k}{2}\leq n$ is equivalent to $(2k-1)^2 \leq 8n+1$, hence the largest triangular number $\leq n$ is given by $\binom{k}{2}$ with: $$k = \left\lfloor \frac{1+\sqrt{8n+1}}{2}\right\rfloor.$$
• That was easier than I anticipated...should have known that you could floor out the $r$. Thanks! Commented Sep 1, 2015 at 22:07
• @Lalaloopsy: it is exactly the same, you are just replacing my $k$ with your $k+1$. Commented Sep 2, 2015 at 0:05
• I think @Lalaloopsy 's inequality is correct and the final result is k=$\lceil\frac{-1+\sqrt{8n+1}}{2}\rceil$. Commented Mar 31, 2020 at 16:26