组合思想的应用(本蒟蒻想不到,先分享为敬)
题目https://www.lanqiao.cn/problems/17166/learning/?contest_id=179
AC代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, INF = 0X3f3f3f3f, eps = 1e-8;
ll n,x;
ll nums[33];
ll C(ll a,ll b)
{
ll res = 1;
for(ll i = b, j = 1; j <= a; j ++, i --)
{
res = res * i / j;
}
return res;
}
void work()
{
cin >> n;
for(int i = 0; i < n; i ++)
{
cin >> x;
int p = 0;
while(x)
{
if(x & 1) nums[p] ++;
x >>= 1;
p ++;
}
}
ll ans = 0;
for(int i = 0; i < 33; i ++) ans += C(2,nums[i]);
cout << ans << endl;
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
work();
return 0;
}