-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem127.nit
60 lines (49 loc) · 1.12 KB
/
problem127.nit
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
53
54
55
56
57
58
59
60
class RadComparator
super Comparator
var rads: Array[Int]
redef type COMPARED: Int
redef fun compare(a, b) do return rads[a] <=> rads[b]
end
var limit = 120000
var sieve = new Array[Bool]
var rads = new Array[Int]
for i in [0..limit[ do
sieve.add(true)
rads.add(1)
end
sieve[0] = false
sieve[1] = false
for i in [0..limit[ do
if sieve[i] then
rads[i] *= i
var j = i + i
while j < limit do
sieve[j] = false
rads[j] *= i
j += i
end
end
end
var comparator = new RadComparator(rads)
var by_radical = new Array[Int].from([1..limit[)
comparator.sort(by_radical)
var total_sum = 0
for c in [1..limit[ do
if rads[c] < c then
for a in by_radical do
var b = c - a
if a >= b or b <= 0 then
continue
end
if rads[c] * rads[a] * 2 > c then
break
end
if a.gcd(b) == 1 then
if rads[a] * rads[b] * rads[c] < c then
total_sum += c
end
end
end
end
end
print total_sum