Source Code
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

vector<long long> pre(100001);
void prepare(){
	pre[1] = 1;
	for(ll i = 2; i < 100001; i++){
		pre[i] = pre[i-1] + (i-1)*(i-2)/2 + (i * i);
	}
}

int main(){
	prepare();
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		cout << pre[n] << endl;	
	}
	// long long sum = 0;
	// ll i = 1;
	// ll n = 100000;
	// while(i <= n){
	// 	sum += (i-1)*n + i;
	// 	i++;
	// }
	// cout << sum << endl;
	// cout << pre[n];
	return 0;
}
Copy
Ali's Game MohaDarkness
GNU G++17
334 ms
2.5 MB
Runtime Error