We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b6736ec commit b0f0a38Copy full SHA for b0f0a38
Day 29: Bitwise AND.py
@@ -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
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