https://ac.nowcoder.com/acm/contest/5600/J
#include<iostream> using namespace std; typedef long long ll; const ll mod = 1e9+7; const int maxn = 2e5+111; int n; ll k_q(ll a,ll b){ ll res = 1; while(b){ if(b&1){ res = (res*a)%mod; } b>>=1; a = (a*a)%mod; } return res%mod; } ll jc[maxn]; ll list[maxn];//list[i]是i的阶乘 ll C(ll n,ll m){ ll ans = (list[n]*((jc[m]*jc[n - m])%mod))%mod; return ans%mod; } ll cnt1[2000];//1 ll cnt0[2000]; int main(){ scanf("%d",&n); list[0] = 1; for(int i=1;i<maxn;i++){ list[i] = (1LL*list[i-1] * i)%mod; } for(int i=0;i<maxn;i++){ jc[i] = k_q(list[i],mod-2)%mod; } int cns=0; for(int i=0;i<n;i++){ ll x; scanf("%lld",&x); for(ll j=0;j<60;j++){ int t = (x>>j)&1; if(t) cnt1[j]++; else cnt0[j]++; } } ll sum = 0; ll ans = 0; for(int i=0;i<60;i++){ if(cnt1[i] == 0) continue; if(cnt1[i]>=3){ ans = (C(cnt1[i],3)*k_q(2,i))%mod; sum = (sum + ans)%mod; } if(cnt0[i] >= 2){ ans = (C(cnt0[i],2)*cnt1[i])%mod; ans = (ans*k_q(2,i))%mod; sum = (sum + ans)%mod; } } cout<<sum<<endl; return 0; }