题意

n面骰子,投m次,若每次均为n则牛牛赢,求牛牛输的概率。(读了半天的赢的概率,wa傻了都)

题解

直接对分母用费马小定理求逆元即可,概率为

code

#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

ll qpow(ll x, ll y)
{
   ll res = 1;
   while(y){
      if(y & 1) res = res * x % mod;
      x = x * x % mod;
      y>>=1;
   }
   return res;
}

int main()
{
   ios;
   int t;
   cin>>t;
   while(t--){
      ll n,m;
      cin>>n>>m;
      ll tmp = qpow(n,m);
      printf("%lld\n",(tmp-1) * qpow(tmp,mod-2) %  mod);
   }


   return 0;
}