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 20:25:17 +02:00

24 lines
442 B
Python

#!/usr/bin/env python3
import sys
def bitwise_difference(A):
l = len(A)
s = 0
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
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))