图片说明

  • 代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
int t;
ll n,m;
inline ll get(ll a,ll b)
{
    ll res=1;
    for (;b;b>>=1,a=a*a%mod)
        if(b&1) res=(res*a)%mod;
    return res;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld",&n,&m);
        ll k=get(n,m);
        ll p=(k+mod-1)%mod;
        printf("%lld\n",p*get(k,mod-2)%mod);
    }

    return 0;
}