Difference between revisions of "TADM2E 2.34"
From Algorithm Wiki
(Created page with "This task refers to this song The_Twelve_Days_of_Christmas_(song) So we have to calculate the sum like this 1 day - 1 gift 2 day - 1 gift + 2 gifts 3 day - 1 + 2 + 3 n day -...") |
|||
Line 1: | Line 1: | ||
This task refers to this song The_Twelve_Days_of_Christmas_(song) | This task refers to this song The_Twelve_Days_of_Christmas_(song) | ||
+ | |||
So we have to calculate the sum like this | So we have to calculate the sum like this | ||
1 day - 1 gift | 1 day - 1 gift | ||
+ | |||
2 day - 1 gift + 2 gifts | 2 day - 1 gift + 2 gifts | ||
+ | |||
3 day - 1 + 2 + 3 | 3 day - 1 + 2 + 3 | ||
+ | |||
n day - 1 + 2 + 3 + ... + n | n day - 1 + 2 + 3 + ... + n | ||
+ | |||
Formula is | Formula is |
Latest revision as of 07:08, 27 May 2020
This task refers to this song The_Twelve_Days_of_Christmas_(song)
So we have to calculate the sum like this
1 day - 1 gift
2 day - 1 gift + 2 gifts
3 day - 1 + 2 + 3
n day - 1 + 2 + 3 + ... + n
Formula is
$ \begin{align} &\sum_{i=1}^n \sum_{j=1}^n j\ = \sum_{i=1}^n \frac{n(n+1)}{2} =\\ &= \frac{1}{2}\sum_{i=1}^n n^2 + \frac{1}{2}\sum_{i=1}^n n=\\ &= \frac{n(n+1)(2n+1) + 3n(n+1)}{12} = \frac{(n+1)(n^2+2n)}{6}\ \end{align} $