CF #737(div2)C. Moamen and XOR,位运算,结论题,推公式

Posted 小哈里

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF #737(div2)C. Moamen and XOR,位运算,结论题,推公式相关的知识,希望对你有一定的参考价值。

problem

C. Moamen and XOR
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Moamen and Ezzat are playing a game. They create an array a of n non-negative integers where every element is less than 2k.

Moamen wins if a1&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 a.

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

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

Each test case consists of one line containing two integers n and k (1≤n≤2⋅105, 0≤k≤2⋅105).

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

Print the result modulo 1000000007 (109+7).

Example
inputCopy
3
3 1
2 1
4 0
outputCopy
5
2
1
Note
In the first example, n=3, k=1. As a result, all the possible arrays are [0,0,0], [0,0,1], [0,1,0], [1,0,0], [1,1,0], [0,1,1], [1,0,1], and [1,1,1].

Moamen wins in only 5 of them: [0,0,0], [1,1,0], [0,1,1], [1,0,1], and [1,1,1].

solution

题意:

  • 给出n和k(<2e5),可以构造任意长度为n且满足ai<2^k的序列,求这些序列中满足全部相&大于等于全部异或(即a1&a2&a3…&an >= a1^a2^a3^…^an的个数),答案%(1e9+7)

思路:

  • 看到2e5的范围,猜想是个结论题,所以打表找规律。
  • 奇数很容易找到,偶数需要额外推一下公式
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;

LL mpow(LL a, LL x) {
	if(x==0)return 1;
	LL t = mpow(a, x>>1);
	if(x%2==0)return t*t%mod;
	return t*t%mod*a%mod;
}
LL inv(LL x, LL p){ return mpow(x,p-2);}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;  cin>>T;
	while(T--){
		int n, k;  cin>>n>>k;
		LL t1 = mpow(2,n-1), t2 = 2*t1%mod;
		if(n%2==1)cout<<mpow(t1+1,k)<<"\\n";//奇数
		else cout<<((2*mpow(t2,k)+t2*mpow(t1-1,k))%mod*inv(t2+2,mod))%mod<<"\\n";//偶数
	}
	return 0;
}



以上是关于CF #737(div2)C. Moamen and XOR,位运算,结论题,推公式的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #737 (Div. 2) 1557. C. Moamen and XOR(组合数,位)

cf1557 C. Moamen and XOR

CF #737(div2)A. Ezzat and Two Subsequences,贪心

CF #727(div2)C. Stable Groups,贪心,排序

CF #738(div2)C. Mocha and Hiking(构造)

CF #724(div2)C. Diluc and Kaeya,暴力,构造