O(32n) solution using c++


#1

int Solution::cntBits(vector &A) {
long long p = pow(10,9)+7;
long long n= A.size();
long long count=0;
for(long long i=0;i<32;i++)
{
long long zerocount=0;
long long onecount=0;
for(long long j=0;j<n;j++)
{
if(A[j]&(1<<i))
{
onecount++;
}
else
{
zerocount++;
}
}
count = ((count%p) + (((onecount%p)(zerocount%p))%p2)%p)%p;
}
return count%p;
}