This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
ProgrammingChallenges/bit_difference.py

25 lines
442 B
Python
Raw Normal View History

2019-04-04 15:04:30 +00:00
#!/usr/bin/env python3
import sys
def bitwise_difference(A):
2019-04-04 18:25:17 +00:00
l = len(A)
2019-04-04 15:04:30 +00:00
s = 0
2019-04-04 18:25:17 +00:00
for i in range(32):
n1 = 0
for j in range(l):
n1 += A[j] & 1
A[j] = A[j] >> 1
n0 = l - n1
s += n1 * n0
2019-04-04 15:04:30 +00:00
return s
if __name__ == "__main__":
sys.stdin.readline()
A = sys.stdin.readline().split()
for i in range(len(A)):
A[i] = int(A[i])
print(bitwise_difference(A))