Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for the problem Sum of series : we just have to calculate Sn the sum of consecutive terms of an arithmetic progression (suite arithmétique)
- with Tn = n^2*(n - 1 )^2 ; (^ is power).
- Sn = T1 + T2 + .... + Tn .
- with some basic knowledge in math we can prove that Tn = 2*n - 1 . we know that the sum of consecutive terms of an arithmetic progression is (n + k - 1 ) *( (Nth term + Kth term )/2 ). Nth is the last term. Kth is the first term.
- T1 = 2 * 1 - 1 = 1 ;
- so Sn = (n + 1 - 1 ) * ( ( 2 * n - 1 + 1 ) / 2 ) = n * (( 2 * n ) / 2 ) ) = n ^ 2 ;
- so the solution is n^2 .
- then after reading the input n ( n <= 10^10 ) we have to do n % 10^9 + 7 , so we can avoid an overflow ( surpassing the max value of long int (10^18) ) .
- We can prove it also by writing some examples on paper :
- if n == 1 sol is 1
- if n == 2 sol is 4
- if n == 3 sol is 9
- and so on ...
- Sorry for for the bad explanation for the problem earlier. it happens sometimes. hope that you can understand it now.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement