25 lines
486 B
Text
25 lines
486 B
Text
function SumProperDivisors(number)
|
|
if number < 2 then return 0
|
|
sum = 0
|
|
for i = 1 to number \ 2
|
|
if number mod i = 0 then sum += i
|
|
next i
|
|
return sum
|
|
end function
|
|
|
|
dim sum(20000)
|
|
for n = 1 to 19999
|
|
sum[n] = SumProperDivisors(n)
|
|
next n
|
|
|
|
print "The pairs of amicable numbers below 20,000 are :"
|
|
print
|
|
|
|
for n = 1 to 19998
|
|
f = sum[n]
|
|
if f <= n or f < 1 or f > 19999 then continue for
|
|
if f = sum[n] and n = sum[f] then
|
|
print rjust(string(n), 5); " and "; sum[n]
|
|
end if
|
|
next n
|
|
end
|