Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function factor{T<:Integer}(n::T)
- 0 < n || error("number to be factored must be positive")
- h = Dict{T,Int}()
- n == 1 && return h
- local s::T, p::T
- s = isqrt(n)
- p = 2
- while p <= s
- if n % p == 0
- while n % p == 0
- h[p] = get(h,p,0) + 1
- n = div(n,p)
- end
- s = isqrt(n)
- end
- p += (p==2 ? 1 : 2)
- end
- return h
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement