search.limit% = 20000 dim sumf%(search.limit%) print "Searching up to"; search.limit%; "for amicable pairs:" rem - create a table of proper divisor sums for a% = 1 to search.limit% sumf%(a%) = 1 next a% for a% = 2 to search.limit% b% = a% + a% while (b% > 0) and (b% <= search.limit%) sumf%(b%) = sumf%(b%) + a% b% = b% + a% wend next a% rem - search for pairs count% = 0 a% = 2 while a% < search.limit% b% = sumf%(a%) rem - protect against invalid array index if b% <= 0 or b% >= search.limit% then b% = 2 rem - otherwise, we're good to go if (b% > a%) and (a% = sumf%(b%)) then \ print using "##### #####"; a%; b% : \ count% = count% + 1 a% = a% + 1 wend print count%; "pairs were found" end