-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay29.java
More file actions
29 lines (27 loc) · 755 Bytes
/
Day29.java
File metadata and controls
29 lines (27 loc) · 755 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
import java.util.*;
public class Solution {
public static int findMaximum(int n, int k){
int max = 0;
int a = n - 1; // we are constrained by a < b
while(a-- > 0) {
for(int b = a + 1; b <= n; b++){
int test = a & b;
if( test < k
&& test > max ){
max = test;
}
}
}
return max;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0; i < t; i++){
int n = in.nextInt();
int k = in.nextInt();
System.out.println( findMaximum(n, k) );
}
in.close();
}
}