forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathANDProduct.java
More file actions
31 lines (29 loc) · 732 Bytes
/
ANDProduct.java
File metadata and controls
31 lines (29 loc) · 732 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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n--!=0){
long a=sc.nextLong();
long b=sc.nextLong();
long and=a;
if(a%4==0){
for(long i=a+4;i<=b;i+=4){
and&=i;
}
}
else if(a%2==0){
for(long i=a+2;i<=b;i+=2){
and&=i;
}
}
else{
for(long i=a+1;i<=b;i++){
and&=i;
}
}
System.out.println(and);
}
}
}