Divisors

We are often interested in the divisors of a number, \(n\),

function divisors(n::Int)
    n == one(n) && return [one(n)]
    ds = [ 1, n ]
    
    i = 2
    while i ≤ sqrt(n)
        if n % i == 0
            if i != div(n, i)
                ds = vcat(ds, [i, div(n, i)])
            else
                ds = vcat(ds, [i])
            end
        end
        i += 1
    end
    return sort(ds)
end