Comparing Julia and Python for basic operations

One simple speed-up is to replace this line by res = floor(Int, sqrt(n)), as otherwise floor returns a Float64.

On a side note, I wonder if your num_divisors function is correct, as it returns 2 for 9 instead of 3 (unless I have the wrong definition of “divisors”). A fix could be to not pop! when res^2 == n, but instead to substract 1 to the returned result.

2 Likes