标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 681 Accepted Submission(s): 235
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const long long p = 1e9+7; typedef long long LL; LL pow_mod(LL a,LL n) { LL ans=1; while(n) { if(n&1) ans=ans*a%p; a=a*a%p; n>>=1; } return ans; } LL cm(LL n,LL m,LL mod) { if(m>n) return 0; LL i,ans=1,a,b; for(i=0; i<m; i++) { a=(n-i)%mod; b=(m-i)%mod; ans=ans*( a*pow_mod(b,mod-2)%mod )%mod; } return ans; } LL lucas(LL n,LL m,LL p) { if(m==0) return 1; return ( cm(n%p,m%p,p)*lucas(n/p,m/p,p) )%p; } int main() { int T; long long n,m,k; scanf("%d",&T); while(T--) { scanf("%lld %lld %lld",&n,&m,&k); LL a = lucas(n-m*k-1,m-1,p); LL c = pow_mod(m,p-2)%p; printf("%lld\n",((a*n)%p*c)%p); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5890985.html