C++D想要吗。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int f(int a,int b)
{
int r=1;
a%=mod;
while(b)
{
if(b&1)r=r*a%mod;
a=a*a%mod;
b>>=1;
}
return r;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
int x=f(2,mod-2),y=f(24,mod-2);
for(int i=1;i<=T;i++)
{
int n,a=1;
cin>>n;
if(n>=2)a=(a+(n%mod)*((n-1)%mod)%mod*x)%mod;
if(n>=4)a=(a+(n%mod)*((n-1)%mod)%mod*((n-2)%mod)%mod*((n-3)%mod)%mod*y)%mod;
cout<<"Case #"<<i<<": "<<a<<"\n";
}
return 0;
}