Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. for the problem Sum of series : we just have to calculate Sn the sum of consecutive terms of an arithmetic progression (suite arithmétique)
  2. with Tn = n^2*(n - 1 )^2 ; (^ is power).
  3. Sn = T1 + T2 + .... + Tn .
  4. 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.
  5. T1 = 2 * 1 - 1 = 1 ;
  6. so Sn = (n + 1 - 1 ) * ( ( 2 * n - 1 + 1 ) / 2 ) = n * (( 2 * n ) / 2 ) ) = n ^ 2 ;
  7. so the solution is n^2 .
  8. 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) ) .
  9. We can prove it also by writing some examples on paper :
  10. if n == 1 sol is 1
  11. if n == 2 sol is 4
  12. if n == 3 sol is 9
  13. and so on ...
  14. 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