Source Code
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
#include<iomanip>
#include <numeric>
#include<iomanip>
#include <bitset>
#define OmarNasr {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
using namespace std;

int main()
{
    OmarNasr;
    int t,n;
    cin >> t;
    while (t--) {
        cin >> n;
        long long sum = 0, c = 1;
        for (int i = 1; i <= n; i++) {
            sum += (i - 1) * n + c;
            c++;
        }
        cout << sum << "\n";
    }
    return 0;
}
Copy
Ali's Game OmarNasr
GNU G++17
2032 ms
1.6 MB
Time Limit Exceeded