Source Code
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    vector<long long> ans(1000000+1,0);
    long long int sum =0;
    for(int i = 1;i<=1000000;i++)
    {
         sum+=(i*(i+1)-i);
         ans[i] = sum;
    }
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<ans[n]<<endl;
    }
}
Copy
Ali's Game moathhamudah
GNU G++17
7 ms
8.0 MB
Wrong Answer