P5390 [Cnoi2019] 数学作业 题解
题目传送门
又是一个数学作业……
分析
不要小看这道题!
随便跳到的。
一看到这道题,就想着去算每个数的贡献。但是发现 加 和 异或 两个运算不满足可加性,所以有点麻烦。但是,既然是异或,那还是考虑 摆烂 拆位吧。
将所有数拆位,考虑第
由于是异或,肯定一半为
0 ,一半为1 。——from https://www.luogu.com.cn/blog/Isaunoya/solution-p5390
这个东西过于神仙,所以我们可能需要稍微解释一下。当然你也可以看 Little09 大佬的。
个人认为比较严谨的数学证明
首先先不考虑那些为
只需证
所以答案应该是
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
ll inline read()
{
ll num=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){num=(num<<3)+(num<<1)+(ch^48);ch=getchar();}
return num*f;
}
ll T,n,ans;
ll qp(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1)res=(res*a)%mod;
a=(a*a)%mod;b>>=1;
}
return res;
}
void solve()
{
n=read();ans=0;
for(int i=1;i<=n;i++)ans|=read();
ans=ans*qp(2,n-1)%mod;
printf("%lld\n",ans);
}
int main(){
T=read();
while(T--)solve();
return 0;
}