1234567891011121314151617181920212223242526272829303132
#include <iostream> #include<cmath> using namespace std; int main(int argc, char *argv[]) { int div; div=(1e+9)+7; int T,n; int sum=0; cin>>T; if(T>10) { return 1;; } for(int i=1;i<=T;i++) { sum=0; cin>>n; if(n>(1e+16)) { return 2; } for(int j=1;j<=n;j++) { sum=sum+(j*j-(j-1)*(j-1)); } sum=sum%div; cout<<sum<<endl; } return 0; }
Sn = Tn + Tn-1 + Tn-2 + ... + T2 + T1 T(n) = n2 - (n - 1)2
Sn = n2 - (n - 1)2 + (n - 1)2 - (n - 2)2 + (n - 2)2 - (n - 3)2 + ... + 22 - 12 + 12 - 02