题目链接:
hannnnah_j’s Biological TestTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 412 Accepted Submission(s): 129
One day, she wants to test m students, thus she arranges n different seats around a round table.
In order to prevent cheating, she thinks that there should be at least k empty seats between every two students.
hannnnah_j is poor at math, and she wants to know the sum of the solutions.So she turns to you for help.Can you help her? The answer maybe large, and you need to mod 1e9+7.
The next T lines were given n, m, k, respectively.
0 < m < n < 1e6, 0 < k < 1000
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> #include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar()); for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + '0'); putchar('\n'); } const LL mod=1e9+7; const double PI=acos(-1.0); const LL inf=1e18; const int N=(1<<20)+10; const int maxn=1e6+10; const double eps=1e-12; int n,m,k; LL p[maxn]; inline void Init() { p[0]=1; p[1]=1; for(int i=2;i<maxn;i++)p[i]=p[i-1]*(LL)i%mod; } LL pow_mod(LL x,LL y) { LL s=1,base=x; while(y) { if(y&1)s=s*base%mod; base=base*base%mod; y>>=1; } return s; } int main() { //freopen("int.txt","r",stdin); Init(); int t; read(t); while(t--) { read(n);read(m);read(k); if(m==1){printf("%d\n",n);continue;} if(n<m*(k+1))printf("0\n"); else { int fn=n-k*m-1,fm=m-1; LL ans=p[fn]*pow_mod(p[fm]*p[fn-fm]%mod,mod-2)%mod; ans=ans*n%mod*pow_mod((LL)m,mod-2)%mod; printf("%lld\n",ans); } } return 0; }