C. Moamen and XOR
题目链接
【题目大意】
给定n,k,要求统计出有多少个包含n个小于2^n的整数序列满足其与运算结果大于等于异或运算结果
【思路】
统计每一位贡献的答案
分成两类
【代码如下】
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int Power(int x,int y){
int r=1;
while(y){
if(y&1)r=1ll*r*x%mod;
x=1ll*x*x%mod,y>>=1;
}
return r;
}
int main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
// cout<<Power(Power(2,0),n)<<endl;
int prod=1,ans=0;
for(int i=k-1;i>=0;i--){
if(n%2==0)ans=(ans+1ll*prod*Power(Power(2,i),n))%mod;
int u=0;
u=Power(2,n-1);
if(n%2==0)u=(u-1+mod)%mod;
if(n&1)u=(u+1)%mod;
prod=1ll*prod*u%mod;
}
ans=(ans+prod)%mod;
cout<<ans<<‘\n‘;
}
return 0;
}
Codeforces Round #737 (Div. 2)-C
原文:https://www.cnblogs.com/DonaKui/p/15126123.html