标签:cas output mis bsp with nes limit content other
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1868 Accepted Submission(s): 522
代码:
1 #include<bits/stdc++.h> 2 //#include<regex> 3 #define db double 4 #include<vector> 5 #define ll long long 6 #define vec vector<ll> 7 #define Mt vector<vec> 8 #define ci(x) scanf("%d",&x) 9 #define cd(x) scanf("%lf",&x) 10 #define cl(x) scanf("%lld",&x) 11 #define pi(x) printf("%d\n",x) 12 #define pd(x) printf("%f\n",x) 13 #define pl(x) printf("%lld\n",x) 14 #define MP make_pair 15 #define PB push_back 16 #define inf 0x3f3f3f3f3f3f3f3f 17 #define fr(i,a,b) for(int i=a;i<=b;i++) 18 const int N=1e5+5; 19 const int mod=1e9+7; 20 const int MOD=mod-1; 21 const db eps=1e-18; 22 const db PI=acos(-1.0); 23 using namespace std; 24 ll x; 25 ll F[N],inv[N],Finv[N]; 26 bool cal(ll n){ 27 if((n*n+n-2)/2<=x) return 1; 28 return 0; 29 } 30 31 void init(){ 32 inv[1] = 1; 33 for(int i = 2; i < 45000; i ++){ 34 inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;//单个逆元 35 } 36 F[1] = Finv[1] = 1; 37 for(int i = 2; i < 45000; i ++){ 38 F[i] = F[i-1] * 1ll * i % mod;//阶乘 39 Finv[i] = Finv[i-1] * 1ll* inv[i] % mod;//逆元阶乘 40 } 41 } 42 int main(){ 43 //freopen("data.in","r",stdin); 44 //freopen("data.out","w",stdout); 45 int t; 46 ci(t); 47 init(); 48 while(t--) 49 { 50 cl(x); 51 if(x<5) {pl(x);continue;} 52 ll l=2,r=45000,sum; 53 while(l<r){ 54 ll mid=l+(r-l+1)/2; 55 if(cal(mid)) l=mid; 56 else r=mid-1; 57 } 58 ll ans=x-(l*l+l-2)/2; 59 if(ans==l) sum=F[l+2]*inv[2]%mod*inv[l+1]%mod; 60 else sum=F[l+1]*Finv[l-ans+1]%mod*F[l-ans]%mod; 61 pl(sum); 62 } 63 return 0; 64 }
标签:cas output mis bsp with nes limit content other
原文地址:http://www.cnblogs.com/mj-liylho/p/7625949.html