Source Code
#include <iostream>
using namespace std;

void solve(){
	int n;
	cin>>n;
	int grid[n][n];
	int cnt=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){grid[i][j]=cnt; cnt++;}
	}
	
	int sum=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) {
			if(i==j) sum+=grid[i][j];
		}
	}
	cout<<sum<<endl;
}

int main() {
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
Copy
Ali's Game lianattily
GNU G++17
2066 ms
10.5 MB
Time Limit Exceeded