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

举报
小哈里 发表于 2022/05/10 23:50:04 2022/05/10
【摘要】 problem C. Moamen and XOR time limit per test2 seconds memory limit per test256 megabytes inputstanda...

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;
}




  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。

原文链接:gwj1314.blog.csdn.net/article/details/119581546

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。