A.Eddy Walker
Meaning of the questions : give your circle of length n (n total points (0 ~ n-1), in order to form a ring), each time a random walk step by step to the right or to the left, you finally ask all points walked at least once, the last step in the handover probability m is the number of points.
This problem is mainly subject few people can read, like reading comprehension same article, you will find you will understand the probability of finding the falls 0 to n-1 are the same, T set of sample, every time the probability must be multiplied by the probability of before, and finally remember to add special sentence
#include<iostream> #include<cstdio> using namespace std; typedef long long ll; const int mod=1e9+7; ll n, m, ans; ll mod_pow(ll x, ll n) { ll res = 1; while (n>0) { if (n&1) res = res*x%mod; x = x*x%mod; n >>= 1; } return res; } int main() { int t; scanf("%d",&t); ans = 1; while(t--){ scanf("%d%d",&n,&m); if(n==1 && m==0) ans *= 1; else if(m==0) ans *= 0; else ans = (ans*mod_pow(n-1,mod-2))%mod; printf("%lld\n",ans); } return 0; }