题意
eddy走一个长度为(n)的环,每次能往前或往后走一步,问走到(m)点恰好走完所有点至少一次的概率,前(i)个询问的答案要乘起来
分析
- (n=1,m=0),答案为(1)
- (n>1,m=0),答案为(0)
- (n>1,m e 0),答案为(1/(n-1))
Code
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
int T;
ll n,m;
ll ksm(ll a,ll b){
ll ret=1;
while(b){
if(b&1) ret=ret*a%mod;
b>>=1;
a=a*a%mod;
}
return ret;
}
int main(){
//ios::sync_with_stdio(false);
//freopen("in","r",stdin);
scanf("%d",&T);
ll ans=1;
while(T--){
scanf("%lld%lld",&n,&m);
if(n==1) printf("%lld
",ans);
else{
if(m==0){
ans=0;
printf("%lld
",ans);
}else{
printf("%lld
",(ans*=ksm(n-1,mod-2))%=mod);
}
}
}
return 0;
}