blob: 092419a53d2a3c0bb6ebeb8f9b47214dd4198082 (
plain)
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
|
public class gcd
{
public static int gcd2(int a, int b) {
int c;
while (b != 0) {
c = b;
b = a % b;
a = c;
}
return a;
}
public static int gcdn(int [] a) {
int r = a[0];
for (int i = 1; i < a.length; i++)
r = gcd2(r, a[i]);
return r;
}
public static void main(String [] argv) {
int [] n = new int [argv.length];
for (int i = 0; i < argv.length; i++) {
n[i] = Integer.parseInt(argv[i]);
}
System.out.println(gcdn(n));
}
}
|