Abundant, deficient and perfect number classifications: Difference between revisions

m
m (→‎{{header|Julia}}: use divisors())
m (→‎Using Primes versions >= 0.5.4: use array to tuple)
Line 3,293:
<syntaxhighlight lamg = "julia">using Primes
 
""" Return tuple of (perfect, abundant, deficient) counts from 1 up to nmax """
function per_abu_def_classify(nmax::Int)
nperfect, nabundant, ndeficientresults = [0, 0, 0]
for n in 1:nmax
tsum = results[sign(sum(divisors(n)) - 2 * n) + 2] += 1
if tsum == n
nperfect += 1
elseif tsum > n
nabundant += 1
elseif tsum < n
ndeficient += 1
end
end
return nperfect(perfect, nabundantabundant, ndeficientdeficient) = results
end
 
4,108

edits