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. 


 
' FreeBASIC v1.05.0 win64
 
Function SumProperDivisors(number As Integer) As Integer
  If number < 2 Then Return 0
  Dim sum As Integer = 0
  For i As Integer = 1 To number \ 2
    If number Mod i = 0 Then sum += i
  Next
  Return sum
End Function
 
Dim As Integer n, f
Dim As Integer sum(19999)
 
For n = 1 To 19999
  sum(n) = SumProperDivisors(n)
Next
 
Print "The pairs of amicable numbers below 20,000 are :"
Print
 
For n = 1 To 19998
  ' f = SumProperDivisors(n)
  f = sum(n)
  If f <= n OrElse f < 1 OrElse f > 19999 Then Continue For 
  If f = sum(n) AndAlso n = sum(f) Then
    Print Using "#####"; n;  
    Print " and "; Using "#####"; sum(n)
  End If
Next
 
Print
Print "Press any key to exit the program"
Sleep
End
 