Codeforces Round #737 (Div. 2)---C. Moamen and XOR

Codeforces Round #737 (Div. 2)—C. Moamen and XOR

Moamen and Ezzat are playing a game. They create an array aa of nn non-negative integers where every element is less than 2^k.

Moamen wins if a1&a2&a3&…&an≥a1⊕a2⊕a3⊕…⊕ana1&a2&a3&…&an≥a1⊕a2⊕a3⊕…⊕an.

Here && denotes the bitwise AND operation, and ⊕⊕ denotes the bitwise XOR operation.

Please calculate the number of winning for Moamen arrays aa.

As the result may be very large, print the value modulo 1000000007(10e9+7).

Input

The first line contains a single integer tt (1≤t≤5)— the number of test cases.

Each test case consists of one line containing two integers nn and kk (1≤n≤2⋅10^5, 0≤k≤2⋅10^5).

Output

For each test case, print a single value — the number of different arrays that Moamen wins with.

Print the result modulo 1000000007(10e9+7).

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll ksm(ll a,ll b){
    ll ans=1,base=a;
    while(b){
        if(b&1)ans=ans*base%mod;
        base=base*base%mod;
        b>>=1;
    }
    return ans%mod;
}   
int main()
{
    int t;scanf("%d",&t);
    while(t--){
        ll n,k;scanf("%lld %lld",&n,&k);
        ll c=ksm(2,n-1);//每一位相等有多少可能,偶数个1,异或值为0
        //先计算相等的情况
        if(n%2)c=(c+1)%mod;//如果n是奇数,那么存在一种异或值为1的情况,全1
        else c=(c-1+mod)%mod;//如果n是偶数,那么n个数为1的情况不是相等的情况
        ll ans=ksm(c,k);
        if(n%2==0){//只有偶数时存在大于的情况
            for(int i=1;i<=k;i++){//枚举大于的情况,要大于,枚举每一位上与操作为1(全1),异或操作为0的情况
                //当前位右边随便
                ll r=ksm(2,(k-i)*n);
                //当前位左边要相等
                ll l=ksm(c,i-1);
                //当前位全为1
                ans=(ans+l*r%mod)%mod;
                //不会重复是因为,左边的位要全部相等,而左边全部相等,左边的每一位必不可能全为1
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独一无二的VV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值