做题记录整理数论1 P6102 [EER2]谔运算(2022/10/4)

P6102 [EER2]谔运算

位运算题,但是就算进数论里面吧

之前说dp是我学得最烂的(其实都没好到哪里去),现在发现原来数论才是。。。

由于是看题解的,而且数论题看题解和白嫖也差不多了,所以就不总结了。。。
https://studyingfather.blog.luogu.org/solution-p6102

#include<bits/stdc++.h>
#define for1(i,a,b) for(ll i=a;i<=b;i++)
#define ll long long
using namespace std;
ll n,cnt,x,and1,or1;
unsigned int ans,ji[35];
const ll md=(1ll<<32);
int main() 
{
	cin>>n;
	cnt=n*n;
	for1(i,1,n)
	{
		cin>>x;
		ll cnt=0;
		while(x)
		{
			ji[cnt++]+=(int)(x&1);
			x=x>>1;
		}
	}
	for1(i,0,31)
	{
		and1=ji[i]*ji[i],or1=(n-ji[i])*(n-ji[i]);
		ans+=(((and1*or1+(cnt-and1)*(cnt-or1)))<<i);
	}
	cout<<ans<<endl;
	return 0;
}
posted @ 2022-10-04 19:58  yyx525jia  阅读(50)  评论(0)    收藏  举报