According to this video, he explains $$p = k(k+1) / 2$$ Where $p$ is the sum of the first $k$ natural numbers. I understand $k$ means times of repetition and $k+1$ is how it increments, but why does he divide by $2$? I can't justify it.


Here is what the video describes:

for (i = 1; i <= n; i++)
  p += i

$$\begin{array}{|c|c|} \hline i & p \\ \hline 1 & 1 \\ \hline 2 & 3 \\ \hline 3 & 6 \\ \hline 4 & 10 \\ \hline \vdots & \vdots \\ \hline i & i(i+1)/2 \\ \hline \end{array}$$

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 cs.stackexchange
scroll top