blob: a8c8c9c2c4a4cfcdda948e6b945d2cdf5d6a495f (
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
|
#!/usr/local/bin/node
//
// See ../README.md
//
//
// Run as: node ch-1.js < input-file
//
require ('readline')
. createInterface ({input: process . stdin})
. on ('line', line => main (+ line))
function introot (square) {
return (Math . floor (.4 + Math . sqrt (square)))
}
function main (n) {
if (n <= 2) {
console . log (-1)
return
}
let n_sq = n * n
let c = n + 1
let c_sq = n_sq + 2 * n + 1
while (2 * c - 1 <= n_sq) {
let b_sq = c_sq - n_sq
let b = introot (b_sq)
if (b_sq == b * b) {
console . log (n + " " + b + " " + c)
}
c_sq += 2 * c ++ + 1
}
let max_a = Math . floor (n / Math . sqrt (2))
for (let a = 3; a <= max_a; a ++) {
let b_sq = n_sq - a * a
let b = introot (b_sq)
if (b_sq == b * b) {
console . log (a + " " + b + " " + n)
}
}
}
|