-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb086.jl
42 lines (33 loc) · 809 Bytes
/
pb086.jl
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
function cuboids(a::Integer, bc::Integer)
2a < bc && return 0
return a >= bc ? bc >> 1 : a - (bc - 1) >> 1
end
function cuboids(M::Integer)
total = zeros(Int, M)
for u in 1:2isqrt(M)
for v in u-1:-2:1
isone(gcd(u, v)) || continue
x = u^2 - v^2
y = 2u * v
for k in 1:div(M, x)
total[k*x] += cuboids(k * x, k * y)
end
for k in 1:div(M, y)
total[k*y] += cuboids(k * y, k * x)
end
end
end
for t in 2:M
total[t] += total[t-1]
end
return total
end
function problem086()
total = cuboids(4 * 10^5)
T = parse(Int, readline())
for _ in 1:T
N = parse(Int, readline())
println(total[N])
end
end
problem086()