Refactoring for memory allocation improvement

This commit is contained in:
David Doblas Jiménez 2021-07-22 14:52:09 +02:00
parent 7e6e92b13e
commit da0f1ba9a6

View File

@ -36,19 +36,11 @@ function Problem12()
=#
function num_divisors(n)
res = floor(Int, sqrt(n))
divs = Int[]
for i = 1:res
if n % i == 0
append!(divs, i)
end
end
if res^2 == n
pop!(divs)
end
return 2 * length(divs)
r = isqrt(n)
2 * count(n % i == 0 for i in 1:r) - (r^2 == n)
end
triangle = 0
for i in Iterators.countfrom(1)
triangle += i