Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Solution::cntBits(vector<int> &A) {
- int max=*max_element(A.begin(),A.end());
- int size=A.size();
- const unsigned int M = 1000000007;
- long long int sum=0;
- for(int i=0;i<=log2(max);i++)
- {
- int ones=0;
- int zeros=0;
- for(auto x:A)
- {
- if(x&(1<<i))
- ones++;
- else
- zeros++;
- }
- sum%=M;
- int z=(2*ones*zeros);
- sum+=z;
- sum%=M;
- }
- return (sum)%M;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement