-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNOTUNIT.java
More file actions
51 lines (40 loc) · 1.11 KB
/
Copy pathNOTUNIT.java
File metadata and controls
51 lines (40 loc) · 1.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class NOTUNIT {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt(); // Test cases
// Input
for (int iterator = 0; iterator < T; iterator++) {
int A = scanner.nextInt();
int B = scanner.nextInt();
// Logic
int i = A;
int j = i + 1;
boolean result = false;
for (; i < B; i++) {
for (; j <= B; j++) {
if (gcd(i,j) > 1) {
result = true;
break;
}
}
if (result) {
break;
}
}
// Output
if (result) {
System.out.println(i + " " + j);
} else {
System.out.println("-1");
}
}
}
private static int gcd(int i, int j) {
int res = 1;
while (i % res == 0 && j % res == 0) {
res++;
}
return res -1;
}
}