牛客第二场 A
你有n个点(0~n-1),按顺序形成一个环,初始时你在0的位子,你随机顺时针走一步或者逆时针走一步,
一旦你走到一个点后,环上所有点都被经过至少一次后,你就必须停下来。
问你最后停留在m这个位子的概率是多少。
你会发现落在0到n-1上的概率是相同的。。。。但是不会落在0位置处,所以加个判断 快速幂求分数幂就行了
结果输出的是前缀积。。。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9+7;
ll pow_mod(ll a,ll b){
ll cnt=1;
while(b){
if(b&1)
cnt=cnt*a%mod;
a=a*a%mod;
b>>=1;
}
return cnt;
}
int main()
{
int t;
ll m,n,ans = 1;
cin>>t;
while(t--)
{
scanf("%lld%lld",&n,&m);
if(m == 0)
{
if(n>1)
ans = 0;
}
else{
ans = ans*pow_mod(n-1,mod-2)%mod;
}
cout<<ans<<endl;
}
return 0;
}

京公网安备 11010502036488号