标签:frame find not printf ant nbsp planet amp assigned
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int MAXN=1e5+5; const LL MOD=1e9+7; int has[MAXN],sum[MAXN],inv[MAXN],tot; LL pro[MAXN]; int get_inv(int x) { if(x==1)return 1; return (MOD-MOD/x)*get_inv(MOD%x)%MOD; } void table() { has[2]=5; tot=2; while(has[tot]<=1e9) { tot++; has[tot]=has[tot-1]+tot+1; } sum[1]=2; for(int i=2;sum[i-1]<=1e9;i++) sum[i]=sum[i-1]+i+1; inv[1]=pro[1]=1; for(int i=2;i<MAXN;i++) (pro[i]=pro[i-1]*i)%=MOD,inv[i]=get_inv(pro[i]); for(int i=2;i<MAXN;i++) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD; } void solve(int x) { int num=upper_bound(has+2,has+tot,x)-has-1; int more=x-sum[num]; int l,r; l=2+more/num; r=l+num-1; LL res; if(more%num) res=pro[r+1]*inv[l-1]%MOD*inv[r+1-more%num]%MOD; else res=pro[r]*inv[l-1]%MOD; printf("%lld\n",res); } int main() { table(); int T; scanf("%d",&T); while(T--) { int x; scanf("%d",&x); if(x==1||x==2||x==3||x==4) { printf("%d\n",x); continue; } solve(x); } return 0; }
标签:frame find not printf ant nbsp planet amp assigned
原文地址:http://www.cnblogs.com/homura/p/6040850.html