题目链接:https://ac.nowcoder.com/acm/contest/882/A
题意:n个点的环,初始在0,可以随机向前向后,n个位置都走完,最后停在m的概率,最后输出前i组概率的乘积
题解:打表发现,1 ~ n-1的点概率为,特别情况,n=1,m=0概率为1,其他m=0概率为0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<list>
#include<stack>
#include<queue>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
//bool vis[1005];
//int num[1005];
const int mod=1e9+7;
ll ksm(ll a,ll b){
ll s=1;
while(b){
if(b&1){
s%=mod;
a%=mod;
s*=a;
}
a%=mod;
a*=a;
b>>=1;
}
return s%mod;
}
int main(){
// 随机数求概率,找规律
// srand((unsigned)time(NULL));
// int n;
// while(cin>>n){
// memset(num,0,sizeof(num));
// for(int i=1;i<=1000000;i++){
// memset(vis,0,sizeof(vis));
// int pos=0;
// int cnt=1;
// vis[0]=true;
// while(cnt<n){
// int f=rand()%2;
// if(!f) f=-1;
// pos+=f;
// pos=(pos%n+n)%n;
// if(!vis[pos]){
// vis[pos]=true;
// cnt++;
// }
// if(cnt==n){
// num[pos]++;
// }
// }
// }
// for(int i=0;i<n;i++){
// cout<<i<<": "<<num[i]<<endl;
// }
// }
int T;
scanf("%d",&T);
ll ans=1;
while(T--){
ll cnt;
int n,m;
scanf("%d%d",&n,&m);
if(n==1&&m==0) cnt=1;
else if(n>1&&m==0) cnt=0;
else if(n>1&&m>0) cnt=ksm(n-1,mod-2);
ans*=cnt;
ans%=mod;
printf("%lld\n",ans);
}
return 0;
}