-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVa_11827.java
More file actions
executable file
·43 lines (34 loc) · 865 Bytes
/
UVa_11827.java
File metadata and controls
executable file
·43 lines (34 loc) · 865 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
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
public class UVa_11827 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner(System.in);
while (keyboard.hasNextInt()) {
int num = keyboard.nextInt();
keyboard.nextLine();
for (int i = 0; i < num; i++) {
String s = keyboard.nextLine();
s = s.trim();
String s_arr[] = s.split(" ");
int max = 1;
for (int k = 0; k < s_arr.length; k++) {
for (int j = k + 1; j < s_arr.length; j++) {
if (gcd(Integer.valueOf(s_arr[k]),
Integer.valueOf(s_arr[j])) > max)
max = gcd(Integer.valueOf(s_arr[k]),
Integer.valueOf(s_arr[j]));
}
}
System.out.println(max);
}
}
}
static int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
}