Difference between revisions of "Talk:Algo-analysis-TADM2E"

From Algorithm Wiki
Jump to: navigation, search
(Created page with "Hello, I have a solution to the task 2-34 (TADM2E 2.34) but I have no permissions to created/edit anything. Here is the solution: This task refers to this song The_Twelve_Da...")
 
Line 3: Line 3:
 
Here is the solution:
 
Here is the solution:
  
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
  

Revision as of 09:31, 26 May 2020

Hello, I have a solution to the task 2-34 (TADM2E 2.34) but I have no permissions to created/edit anything.

Here is the solution:

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