Problem Statement
This problem is a programming version of Problem 6 from projecteuler.net
The sum of the squares of the first ten natural numbers is,12+22+...+102=385 .
The square of the sum of the first ten natural numbers is, (1+2+⋯+10)2=552=3025 .
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025−385=2640 .
Find the difference between the sum of the squares of the firstN natural numbers and the square of the sum.
Input Format
First line containsT that denotes the number of test cases. This is followed by T lines, each containing an integer, N .
Output Format
Print the required answer for each test case.
Constraints1≤T≤104
1≤N≤104
Sample Input
The sum of the squares of the first ten natural numbers is,
Find the difference between the sum of the squares of the first
Input Format
First line contains
Output Format
Print the required answer for each test case.
Constraints
Sample Input
2
3
10
Sample Output 22
2640
MY SOLUTION:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
long int t;
scanf("%ld",&t);
while(t--)
{
long int n;
scanf("%ld",&n);
printf("%ld\n",(long int)pow(n*(n+1)/2,2)-(n*(n+1)*(2*n+1))/6);
}
return 0;
}