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
2019-04-04 17:04:30 +02:00

28 lines
501 B
Python

#!/usr/bin/env python3
import sys
def xor_count(a, b):
xor = a ^ b
i = 0
while xor != 0:
i = i + (xor & 1)
xor = xor >> 1
return i
def bitwise_difference(A):
s = 0
for i in range(len(A)):
for j in range(i+1,len(A)):
s = s + xor_count(A[i], A[j])
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))