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. 


100 DECLARE EXTERNAL FUNCTION sum_proper_divisors
110 CLEAR
120 !
130 DIM f(20001)      ! sum of proper factors for each n
140 FOR i=1 TO 20000
150    LET f(i)=sum_proper_divisors(i)
160 NEXT i
170 ! look for pairs
180 FOR i=1 TO 20000
190    FOR j=i+1 TO 20000
200       IF f(i)=j AND i=f(j) THEN
210          PRINT "Amicable pair ";i;" ";j
220       END IF
230    NEXT j
240 NEXT i
250 !
260 PRINT
270 PRINT "-- found all amicable pairs"
280 END
290 !
300 ! Compute the sum of proper divisors of given number
310 !
320 EXTERNAL FUNCTION sum_proper_divisors(n)
330 !
340 IF n>1 THEN ! n must be 2 or larger
350    LET sum=1 ! start with 1
360    LET root=SQR(n)    ! note that root is an integer
370    ! check possible factors, up to sqrt
380    FOR i=2 TO root
390       IF MOD(n,i)=0 THEN
400          LET sum=sum+i     ! i is a factor
410          IF i*i<>n THEN    ! check i is not actual square root of n
420             LET sum=sum+n/i  ! so n/i will also be a factor
430          END IF
440       END IF
450    NEXT i
460 END IF
470 LET sum_proper_divisors = sum
480 END FUNCTION