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. 


INCLUDE "H6:SIEVE.ACT"
 
CARD FUNC SumDivisors(CARD x)
  CARD i,max,sum
 
  sum=1 i=2 max=x
  WHILE i<max
  DO
    IF x MOD i=0 THEN
      max=x/i
      IF i<max THEN
        sum==+i+max
      ELSEIF i=max THEN
        sum==+i
      FI
    FI
    i==+1
  OD
RETURN (sum)
 
PROC Main()
  DEFINE MAXNUM="20000"
  BYTE ARRAY primes(MAXNUM+1)
  CARD m,n
 
  Put(125) PutE() ;clear the screen
  Sieve(primes,MAXNUM+1)
  FOR m=1 TO MAXNUM-1
  DO
    IF primes(m)=0 THEN
      n=SumDivisors(m)
      IF n<MAXNUM AND primes(n)=0 AND n>m THEN
        IF m=SumDivisors(n) THEN
          PrintF("%U %U%E",m,n)
        FI
      FI
    FI
  OD
RETURN