Amicable pairs: Difference between revisions
Content added Content deleted
(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: | Line 611: | ||
OD; |
OD; |
||
# find the amicable pairs up to 20 000 # |
# find the amicable pairs up to 20 000 # |
||
FOR p1 TO UPB pd sum DO |
FOR p1 TO UPB pd sum - 1 DO |
||
INT pd sum p1 = pd sum[ p1 ]; |
|||
IF pd sum p1 > p1 AND pd sum p1 <= UPB pd sum THEN |
|||
IF pd sum[ pd sum p1 ] = p1 THEN |
|||
print( ( whole( p1, -6 ), " and ", whole( |
print( ( whole( p1, -6 ), " and ", whole( pd sum p1, -6 ), " are an amicable pair", newline ) ) |
||
FI |
FI |
||
FI |
|||
OD |
OD |
||
END |
END |