RosettaCodeData/Task/Arithmetic-Rational/Julia/arithmetic-rational.julia

8 lines
271 B
Text
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
using Primes
divisors(n) = foldl((a, (p, e)) -> vcat((a * [p^i for i in 0:e]')...), factor(n), init=[1])
2015-11-18 06:14:39 +00:00
2020-02-17 23:21:07 -08:00
isperfect(n) = sum(1 // d for d in divisors(n)) == 2
lo, hi = 2, 2^19
println("Perfect numbers between ", lo, " and ", hi, ": ", collect(filter(isperfect, lo:hi)))