blob: 722b6d0f81082b7b8cdb1bfd3d0d65b37dd8e5f7 (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
//
// See ../README.md
//
//
// Run as: ln ch-1.java ch1.java; javac ch1.java; java ch1 < input-file
//
import java.util.*;
public class ch1 {
public static long introot (long square) {
return ((long) Math . floor (Math . sqrt (square)));
}
public static void main (String [] args) {
Scanner scanner = new Scanner (System . in);
while (scanner . hasNextInt ()) {
long n = scanner . nextInt ();
if (n <= 2) {
System . out . println ("-1");
continue;
}
long n_sq = n * n;
long c = n + 1;
long c_sq = n_sq + 2 * n + 1;
while (2 * c - 1 <= n_sq) {
long b_sq = c_sq - n_sq;
long b = introot (b_sq);
if (b_sq == b * b) {
System . out . printf ("%d %d %d\n", n, b, c);
}
c_sq += 2 * c + 1;
c += 1;
}
long max_a = (long) Math . floor (n / Math . sqrt (2));
long a = 3;
for (a = 3; a <= max_a; a ++) {
long b_sq = n_sq - a * a;
long b = introot (b_sq);
if (b_sq == b * b) {
System . out . printf ("%d %d %d\n", a, b, n);
}
}
}
}
}
|