0
$\begingroup$

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?

  • 3
    Quadratic equation: $M^2+M=2N$2017-01-22
  • 0
    Thanks. Is there a ready formula that can find such M?2017-01-22

1 Answers 1

1

$$ \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} $$

  • 0
    Do these brackets mean round down?2017-01-26
  • 0
    @BaimyrzaShamyr: Yes. See [Floor Function](https://en.wikipedia.org/wiki/Floor_and_ceiling_functions).2017-01-26
  • 0
    Bravo! Simple and Impressive solution.2017-01-26