Guest User

Untitled

a guest
May 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. cin>>n;
  7. int A[n];
  8. for(int i = 0; i < n; i++)
  9. cin>>A[i];
  10. int int_size = sizeof(int);
  11. long long int sum = 0;
  12. for(int i = 0; i < int_size*8; i++)
  13. {
  14. int count1 = 0; // Count of 1s in i th bit location in all numbers in array
  15. for(int j = 0; j < n; j++)
  16. {
  17. // Check if i th bit is 1
  18. if(A[j] & 1<<i)
  19. count1++;
  20. }
  21. sum += count1 * (n-count1); // nC2 - count1C2 - (n-count1)C2
  22. }
  23. sum = 2 * sum;
  24. cout<<sum;
  25. return 0;
  26. }
Add Comment
Please, Sign In to add comment