18 lines
572 B
Plaintext
18 lines
572 B
Plaintext
// find amicable pairs p1, p2 where each is equal to the other's proper divisor sum
|
|
|
|
MAX_NUMBER = 20000
|
|
pdSum = [1] * ( MAX_NUMBER + 1 ) // table of proper divisors
|
|
for i in range( 2, MAX_NUMBER )
|
|
for j in range( i + i, MAX_NUMBER, i )
|
|
pdSum[ j ] += i
|
|
end for
|
|
end for
|
|
// find the amicable pairs up to 20 000
|
|
ap = []
|
|
for p1 in range( 1, MAX_NUMBER - 1 )
|
|
pdSumP1 = pdSum[ p1 ]
|
|
if pdSumP1 > p1 and pdSumP1 <= MAX_NUMBER and pdSum[ pdSumP1 ] == p1 then
|
|
print str( p1 ) + " and " + str( pdSumP1 ) + " are an amicable pair"
|
|
end if
|
|
end for
|