NC243339. 被抓住的小竹
描述
输入描述
第一行一个正整数。
接下来行,每行一个正整数
。
输出描述
行,每行一个整数,为所求式子的值。
示例1
输入:
2 2 3
输出:
5 135
C++(clang++ 11.0.1) 解法, 执行用时: 13ms, 内存消耗: 8228K, 提交时间: 2022-11-11 20:11:57
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=1e6+3,H=1e9+7; ll n,p,jc[N]; ll K(ll x,ll y) { ll s=1; while(y) { if(y%2)s=s*x%H; x=x*x%H;y/=2; } return s; } void Solve() { cin>>n; cout<<n*n%H*(n-1)%H*jc[n+3]%H*p%H<<endl; } int main() { jc[1]=1; for(int i=2;i<N;i++)jc[i]=jc[i-1]*i%H; p=K((ll)96,H-2); int T;cin>>T; while(T--)Solve(); }
C++(g++ 7.5.0) 解法, 执行用时: 13ms, 内存消耗: 8256K, 提交时间: 2022-11-13 16:00:46
#include<iostream> using namespace std;typedef long long ll;const ll N=1e6+3,H=1e9+7;ll n,p,jc[N];ll K(ll x,ll y){ll s=1;while(y){if(y%2)s=s*x%H;x=x*x%H;y/=2;}return s;}void Solve(){cin>>n;cout<<n*n%H*(n-1)%H*jc[n+3]%H*p%H<<endl;}int main(){jc[1]=1;for(int i=2;i<N;i++)jc[i]=jc[i-1]*i%H;p=K((ll)96,H-2);int T;cin>>T;while(T--)Solve();return 0;}
Python3 解法, 执行用时: 96ms, 内存消耗: 8688K, 提交时间: 2023-05-30 19:59:00
mod=10**9+7 fac=[1] for i in range(1,100005): fac.append(i*fac[-1]%mod) t=int(input()) for i in range(t): n=int(input()) print((n+3)*(n+2)*(n+1)*n*n*n*(n-1)*(n-1)//96*fac[n-2]%mod)