Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
|
|
@ -1,24 +1,7 @@
|
|||
function isperfect{T<:Integer}(n::T)
|
||||
!isprime(n) || return false
|
||||
tal = 1//n
|
||||
hi = isqrt(n)
|
||||
if hi^2 == n
|
||||
tal += 1//hi
|
||||
hi -= 1
|
||||
end
|
||||
for i in 2:hi
|
||||
(d, r) = divrem(n, i)
|
||||
if r == 0
|
||||
tal += (1//i + 1//d)
|
||||
end
|
||||
end
|
||||
return tal == 1//1
|
||||
end
|
||||
using Primes
|
||||
divisors(n) = foldl((a, (p, e)) -> vcat((a * [p^i for i in 0:e]')...), factor(n), init=[1])
|
||||
|
||||
lo = 2
|
||||
hi = 2^19
|
||||
println("Searching for perfect numbers from ", lo, " to ", hi, ".")
|
||||
for i in 2:2^19
|
||||
isperfect(i) || continue
|
||||
println(@sprintf("%8d", i))
|
||||
end
|
||||
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)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue