- Code: Select all

#include <stdio.h>

long long calculate(int);

int main() {

int test;

scanf("%d",&test);

if (test>0&&test<=10000) {

long long answer[test];

for (int i = 0; i<test; i++) {

int val;

scanf("%d",&val);

if (val>0&&val<=10000) {

answer[i] = calculate(val);

}

}

for (int i = 0; i<test; i++) {

printf("%lld\n",answer[i]);

}

}

return 0;

}

long long calculate(int n){

long long sum1 = (n*(n+1)*(2*n+1))/6;

long long sum2 = (n*(2+(n-1)))/2;

long long diff = sum2*sum2 - sum1;

return diff;

}