Simple and pretty solution in c++


#1

#define mod 1000000007
int Solution::cntBits(vector &A) {
long long int ans=0;
for(int i=0;i<32;i++){
usigned int x=1<<i;
long long int a=0,b=0;
for(int j=0;j<A.size();j++){
if(A[j]&x){
a++;
}else{
b++;
}
}
ans=(ans%mod+ (2*(a%mod)*(b%mod))%mod)%mod;
}
return ans;
}