Abundant, deficient and perfect number classifications: Difference between revisions

m
→‎{{header|Julia}}: use divisors()
imported>Maxima enthusiast
No edit summary
m (→‎{{header|Julia}}: use divisors())
Line 3,288:
Abundant, 4953
</code>
 
=== Using Primes versions >= 0.5.4 ===
Recent revisions of the Primes package include a divisors() which returns divisors of n including 1 and n.
<syntaxhighlight lamg = "julia">using Primes
 
function per_abu_def_classify(nmax::Int)
nperfect, nabundant, ndeficient = 0, 0, 0
for n in 1:nmax
tsum = sum(divisors(n)) - n
if tsum == n
nperfect += 1
elseif tsum > n
nabundant += 1
elseif tsum < n
ndeficient += 1
end
end
return nperfect, nabundant, ndeficient
end
 
let MAX = 20_000
NPE, NAB, NDE = per_abu_def_classify(MAX)
println("$NPE perfect, $NAB abundant, and $NDE deficient numbers in 1:$MAX.")
end
</syntaxhighlight>{{out}}<pre>4 perfect, 4953 abundant, and 15043 deficient numbers in 1:20000.</pre>
 
=={{header|K}}==
4,106

edits