Amicable pairs: Difference between revisions
m
→{{header|Julia}}: comments editied
m (→{{header|Julia}}: comments editied) |
|||
Line 2,362:
=={{header|Julia}}==
Given <code>factor</code>, it is not necessary to calculate the individual divisors to compute their sum. See [[Abundant,_deficient_and_perfect_number_classifications#Julia|Abundant, deficient and perfect number classifications]] for the details.
It is safe to exclude primes from consideration; their proper divisor sum is always 1.
<lang Julia>using Primes, Printf
Line 2,383 ⟶ 2,382:
dsum -= n
end
▲It is safe to exclude primes from consideration; their proper divisor sum is always 1. Also, this code uses a minor trick to ensure that none of the numbers identified are above the limit. All numbers in the range are checked for an amicable partner, but the pair is cataloged only when the greater member is reached.
function amicables(L = 2*10^7)
acnt = 0
|