## Friday, November 25, 2016

### Sum Square Difference

The sum of the squares of the first ten natural numbers is, . The square of the sum of the first ten natural numbers is, . Hence the absolute difference between the sum of the squares of the first ten natural numbers and the square of the sum is .
Find the absolute difference between the sum of the squares of the first  natural numbers and the square of the sum.
Input Format
First line contains  that denotes the number of test cases. This is followed by  lines, each containing an integer, .
Constraints
Output Format
Print the required answer for each test case.
Sample Input 0
2
3
10

Sample Output 0
22
2640

Explanation 0
NOTE: WRITE YOUR PROGRAM IN COMMENTS SECTION

**********************
PROGRAM
**********************
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
int t;
scanf("%d",&t);
for(int a0 = 0; a0 < t; a0++){
int n;
scanf("%d",&n);
long long x=((n*(n+1))/2);
x=x*x;
long long y=1;
y=y*n;
y=y*(n+1);
y=y*(2*n+1);
y=y/6;
printf("%lld\n",x-y );
}
return 0;
}

Name

Email *

Message *