cd 1420: B`
思路:判断二进制最高位是否相同,相同ans+=1;
#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
#define inf 0x3f3f3f3f
#define lowbit(x)x&-x
using namespace std;
typedef long long ll;
const int maxn = 1000010;
const int mod = 1e9+7;
ll i,j,t;
ll n,ans,sum,cnt,num;
ll a[maxn],b[maxn],flag[maxn];
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(i=0; i<n; i++)
cin>>a[i];
memset(b,0,sizeof(b));
for(i=0; i<n; i++)
for(num=31; num>=0; num--)
{
if(a[i]>>num&1)
{
b[num]++; /*二进制最高位相同个数+1*/
break;
}
}
ans=0;
for(i=0; i<=31; i++)
ans+=b[i]*(b[i]-1)/2;
cout<<ans<<endl;
}
return 0;
}