Two integers 



N


{\displaystyle N}

 and 



M


{\displaystyle M}

 are said to be amicable pairs if 



N
≠
M


{\displaystyle N\neq M}

 and the sum of the proper divisors of 



N


{\displaystyle N}

 (




s
u
m

(

p
r
o
p
D
i
v
s

(
N
)
)


{\displaystyle \mathrm {sum} (\mathrm {propDivs} (N))}

) 



=
M


{\displaystyle =M}

 as well as 




s
u
m

(

p
r
o
p
D
i
v
s

(
M
)
)
=
N


{\displaystyle \mathrm {sum} (\mathrm {propDivs} (M))=N}

.



Example

1184 and 1210 are an amicable pair, with proper divisors:

   1, 2, 4, 8, 16, 32, 37, 74, 148, 296, 592   and 
   1, 2, 5, 10, 11, 22, 55, 110, 121, 242, 605   respectively.


Task

Calculate and show here the Amicable pairs below 20,000; (there are eight).



Related tasks
 Proper divisors
 Abundant, deficient and perfect number classifications
 Aliquot sequence classifications and its amicable classification. 


get "libhdr"
 
manifest $(
    MAXIMUM = 20000
$)
 
// Calculate proper divisors for 1..N
let propDivSums(n) = valof
$(  let v = getvec(n)
    for i = 1 to n do v!i := 1
    for i = 2 to n/2 do
    $(  let j = i*2
        while j < n do
        $(  v!j := v!j + i
            j := j + i
        $)
    $)
    resultis v
$)
 
// Are A and B an amicable pair, given the list of sums of proper divisors?
let amicable(pdiv, a, b) = a = pdiv!b & b = pdiv!a
 
let start() be
$(  let pds = propDivSums(MAXIMUM)
    for x = 1 to MAXIMUM do
        for y = x+1 to MAXIMUM do
            if amicable(pds, x, y) do
                writef("%N, %N*N", x, y)
$)