Thx for your answer!
I’ve made a couple of changes (I’m not interested in the divisors themselves, just in the number of them) and now the code runs in 0.12 s
function num_divisors(n)
#res = floor(sqrt(n))
res = floor(Int, sqrt(n))
divs = 0#[]
for i = 1:res
if n % i == 0
divs += 1
#append!(divs, i)
end
end
if res^2 == n
divs -= 1
#pop!(divs)
end
return 2 * divs #length(divs)
end
Regarding the validity of the function, I guess that it’s correct as it gives the solution as good in Project Euler.