Artificial intelligent assistant

Find M <= N such that sum of consequent numbers from 1 to x is M. I am given a number $N$. I need to find $M\le N$ such that $M$ can be written as a sum of consequent numbers from 1 to x. I know this formula $1+2+\cdots +n = \frac{n(n+1)}{2}$. How can I find such M?

$$ \begin{align} &\, M \,=\, \sum_{k=1}^{n}k = \frac{n(n+1)}{2} \le N \\\\[2mm] &\, \frac{n(n+1)}{2}=N \,\Rightarrow\, n^2+n-2N=0 \,\Rightarrow\, n=\frac{-1\pm\sqrt{1+8N}}{2} \\\\[2mm] &\, n\in{\mathbb N}^{+} \,\Rightarrow\, \color{red}{n=\left\lfloor \frac{\sqrt{8N+1}-1}{2} \right\rfloor} ,\,\, \color{blue}{M=\frac{n(n+1)}{2}} \end{align} $$

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 27c6ade6da4cc430aede934a3fa2d36f