Source Code
#include <iostream>
using namespace std;
long long x[(int)1e6+5];
int main() {
	x[1] = 1 ;
	for ( long long i = 2 ; i <= 1e6 ; i++ ) {
		x[i] = i*i+x[i-1]+((i-2)*(i-1)/2) ; 
	}
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		cout << x[n] << endl;
	}
	return 0;
}
Copy
Ali's Game SAAD
GNU G++17
478 ms
10.0 MB
Accepted