Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. void calculateDiff(unsigned longint);
  8.  
  9. void calculateDiff(unsigned long int N){
  10. unsigned long int s1,s2,s3,diff;
  11. s1= (N*(N+1)*(2*N +1))/6;
  12. s2 = (N*(N+1))/2;
  13. s3 = s2*s2;
  14. diff = s3-s1;
  15. cout<<diff<<endl;
  16. }
  17.  
  18. int main() {
  19. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  20. int T;
  21. unsigned long int N;
  22.  
  23. //Get test case
  24.  
  25. cin>>T;
  26.  
  27. //Get Natural Number
  28. for(int i=1;i<=T;i++){
  29. cin>>N;
  30.  
  31. calculateDiff(N);
  32. }
  33.  
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement