Factors of an integer: Difference between revisions

→‎{{header|Julia}}: bugfix for prime n
(→‎{{header|Julia}}: more efficient implementation based on built-in factor function)
(→‎{{header|Julia}}: bugfix for prime n)
Line 1,162:
 
=={{header|Julia}}==
<lang julia>function factors(pn)
f = [one(pn)]
for (p,e) in factor(pn)
f = reduce(vcat, f, [f*p^j for j in 1:e])
end
return length(f) == 1 ? [one(n), n] : sort!(f)
end</lang>
Example output:
Anonymous user