forked from keshavsingh3197/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary.py
More file actions
Latest commit
36 lines (29 loc) · 900 Bytes
/
Copy pathbinary.py
File metadata and controls
36 lines (29 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fromitertoolsimportcombinations
defbinary():
Bin_Dict= {}
foriinnumbers:
Bin_Dict[i] =bin(i)[2:].count('1')
returnBin_Dict
defc():
count=0
foriinrange(1,len(numbers)+1):
forjincombinations(numbers,i):
number_of_ones=0
number_of_zeros=0
forelminj:
number_of_ones+=Bin_Dict[elm]
number_of_zeros+=lar_bit-Bin_Dict[elm]
ifnumber_of_ones==number_of_zeros:
count+=1
returncount
if__name__=='__main__':
N=int(input())
numbers=list(map(int,input().split()))
lar=max(numbers)
lar_bit=len(bin(lar)[2:]) #print upto places
Bin_Dict=binary()
ans=c()
bin_ans=bin(ans)[2:]
iflen(bin_ans) !=lar_bit:
bin_ans='0'*(lar_bit-len(bin_ans))+bin_ans
print(bin_ans)