Amicable pairs: Difference between revisions
Content added Content deleted
(Added Algol W) |
(Added Miniscript) |
||
Line 3,515: | Line 3,515: | ||
12285 14595 |
12285 14595 |
||
17296 18416 |
17296 18416 |
||
</pre> |
|||
=={{header|MiniScript}}== |
|||
{{Trans|ALGOL W}} |
|||
<syntaxhighlight lang="miniscript"> |
|||
// find amicable pairs p1, p2 where each is equal to the other's proper divisor sum |
|||
MAX_NUMBER = 20000 |
|||
pdSum = [1] * ( MAX_NUMBER + 1 ) // table of proper divisors |
|||
for i in range( 2, MAX_NUMBER ) |
|||
for j in range( i + i, MAX_NUMBER, i ) |
|||
pdSum[ j ] += i |
|||
end for |
|||
end for |
|||
// find the amicable pairs up to 20 000 |
|||
ap = [] |
|||
for p1 in range( 1, MAX_NUMBER - 1 ) |
|||
pdSumP1 = pdSum[ p1 ] |
|||
if pdSumP1 > p1 and pdSumP1 <= MAX_NUMBER and pdSum[ pdSumP1 ] == p1 then |
|||
print str( p1 ) + " and " + str( pdSumP1 ) + " are an amicable pair" |
|||
end if |
|||
end for |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
220 and 284 are an amicable pair |
|||
1184 and 1210 are an amicable pair |
|||
2620 and 2924 are an amicable pair |
|||
5020 and 5564 are an amicable pair |
|||
6232 and 6368 are an amicable pair |
|||
10744 and 10856 are an amicable pair |
|||
12285 and 14595 are an amicable pair |
|||
17296 and 18416 are an amicable pair |
|||
</pre> |
</pre> |
||