#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int ksm(int a,int b){
int res=1;
while(b){
if(b&1) res=res*a%mod;
b=b>>1;
a=a*a%mod;
}
return res%mod;
}
int t,n,k;
int32_t main(){
scanf("%lld",&t);
while(t--){
scanf("%lld%lld",&n,&k);
int ans=0;
if(k==0) ans=1;
else if(n%2==1){
int tp=ksm(2,n-1)+1;
ans=ksm(tp,k);
}else{
int tp=ksm(2,n-1)-1;tp=(tp+mod)%mod;
for(int i=0;i<=k;i++){
int tpp=ksm(2,n);tpp%=mod;
int pre=max((int)0,k-i-1);
ans+=ksm(tp,i)*ksm(tpp,pre);
// cout<<i<<" "<<k-i-1<<endl;
ans%=mod;
}
}
cout<<ans<<endl;
}
}
C. Moamen and XOR(组合数+ksm
最新推荐文章于 2023-03-28 21:34:18 发布