forked from dennisnderitu254/Hackerrank-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndProduct.java
More file actions
30 lines (29 loc) · 713 Bytes
/
AndProduct.java
File metadata and controls
30 lines (29 loc) · 713 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
import java.util.*;
import java.io.*;
class AndProduct{
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);
}
}
}