blob: 9e41cf211fc5d75e213d83dd12ff03b094013896 (
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
29
|
// To run:
// $ java ch-1.java 100
// 13015
class Main {
static int gcd(int a, int b) {
while (b != 0) {
int t = b;
b = a % b;
a = t;
}
return a;
}
public static void main(String[] args) {
int n = args.length == 1 ? Integer.parseInt(args[0]) : 3;
int s = 0;
for (int x = 1; x <= n; x++) {
for (int y = x + 1; y <= n; y++) {
s += gcd(x, y);
}
}
System.out.println(s);
}
}
|