Jump to content

Amicable pairs: Difference between revisions

→‎{{header|ALGOL 68}}: Better search algorithm, as in e.g., the PLI-80 sample (but still using a table of divisor sums)
(Added Chipmunk Basic, Gambas, QBasic and True BASIC)
(→‎{{header|ALGOL 68}}: Better search algorithm, as in e.g., the PLI-80 sample (but still using a table of divisor sums))
Line 611:
OD;
# find the amicable pairs up to 20 000 #
FOR p1 TO UPB pd sum - 1 DO
FORINT p2pd FROMsum p1 + 1 TO UPB= pd sum[ p1 DO];
IF pd sum[ p1 ]> = p2p1 AND pd sum[ p2 ]p1 <= p1UPB pd sum THEN
IF pd sum[ pd sum p1 ] = p1 THEN
print( ( whole( p1, -6 ), " and ", whole( p2pd sum p1, -6 ), " are an amicable pair", newline ) )
FI
ODFI
OD
END
3,049

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.