Skip to content

Commit b0f0a38

Browse files
Day 29: Bitwise AND
1 parent b6736ec commit b0f0a38

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Day 29: Bitwise AND.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/python3
2+
import math
3+
import os
4+
import random
5+
import re
6+
import sys
7+
def bitwiseAnd(n,k):
8+
# Write your code here
9+
mx_bit = 0
10+
for i in range(1, n+1):
11+
for j in range(1, i):
12+
bit = i & j
13+
if mx_bit < bit < k:
14+
mx_bit = bit
15+
if mx_bit == k - 1:
16+
return mx_bit
17+
return mx_bit
18+
19+
if __name__ == '__main__':
20+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
21+
t = int(input().strip())
22+
for t_itr in range(t):
23+
first_multiple_input = input().rstrip().split()
24+
count = int(first_multiple_input[0])
25+
lim = int(first_multiple_input[1])
26+
res = bitwiseAnd(count, lim)
27+
fptr.write(str(res) + '\n')
28+
fptr.close()

0 commit comments

Comments
 (0)