Source Code
#include <iostream>
using namespace std;

const int N=1000000+1;
long long freq[N];

void solve()
{
    freq[0]=0;
    freq[1]=1;
    freq[2]=2;
    freq[3]=3;

    long long answer=1000000000+7;
    long long iter=2;
    int weee=1;
    for(int i=4;i<N;i++){
        freq[i]=(freq[i-1]+iter)%answer;
        iter+=weee;
        weee++;
    }
}

int main()
{
    solve();

    int t;cin>>t;
    for(int i=0;i<t;i++){
        int n;cin>>n;
        cout<<freq[n]<<endl;
    }

    return 0;
}
Copy
Study Schedule YousefShaheen
GNU G++17
356 ms
9.0 MB
Wrong Answer