Abundant, deficient and perfect number classifications: Difference between revisions

Content added Content deleted
m (→‎{{header|Julia}}: use divisors())
m (→‎Using Primes versions >= 0.5.4: use array to tuple)
Line 3,293: Line 3,293:
<syntaxhighlight lamg = "julia">using Primes
<syntaxhighlight lamg = "julia">using Primes


""" Return tuple of (perfect, abundant, deficient) counts from 1 up to nmax """
function per_abu_def_classify(nmax::Int)
function per_abu_def_classify(nmax::Int)
nperfect, nabundant, ndeficient = 0, 0, 0
results = [0, 0, 0]
for n in 1:nmax
for n in 1:nmax
tsum = sum(divisors(n)) - n
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
end
return nperfect, nabundant, ndeficient
return (perfect, abundant, deficient) = results
end
end