Julia で Project Euler #3「最大の素因数」

1 min read読了の目安(約500字
function f003(n::Int64)
    factors = []
    rest = n
    while rest % 2 == 0
        rest = rest / 2
        push!(factors, 2)
    end
    i = 3
    while rest > 1
        while rest % i == 0
            rest = rest / i
            push!(factors, i)
        end
        i += 2
    end
    return maximum(factors), factors
end

f003(13195)
# (29, Any[5, 7, 13, 29])

@time f003(600851475143)
# 0.000134 seconds (9 allocations: 256 bytes)
# (6857, Any[71, 839, 1471, 6857])