Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- int A[n];
- for(int i = 0; i < n; i++)
- cin>>A[i];
- int int_size = sizeof(int);
- long long int sum = 0;
- for(int i = 0; i < int_size*8; i++)
- {
- int count1 = 0; // Count of 1s in i th bit location in all numbers in array
- for(int j = 0; j < n; j++)
- {
- // Check if i th bit is 1
- if(A[j] & 1<<i)
- count1++;
- }
- sum += count1 * (n-count1); // nC2 - count1C2 - (n-count1)C2
- }
- sum = 2 * sum;
- cout<<sum;
- return 0;
- }
Add Comment
Please, Sign In to add comment