Amicable pairs: Difference between revisions

Add BCPL
m (→‎{{header|REXX}}: added highlighting to some REXX preambles.)
(Add BCPL)
Line 805:
17296 18416
</pre>
 
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
 
manifest $(
MAXIMUM = 20000
$)
 
// Calculate proper divisors for 1..N
let propDivSums(n) = valof
$( let v = getvec(n)
for i = 1 to n do v!i := 1
for i = 2 to n/2 do
$( let j = i*2
while j < n do
$( v!j := v!j + i
j := j + i
$)
$)
resultis v
$)
 
// Are A and B an amicable pair, given the list of sums of proper divisors?
let amicable(pdiv, a, b) = a = pdiv!b & b = pdiv!a
 
let start() be
$( let pds = propDivSums(MAXIMUM)
for x = 1 to MAXIMUM do
for y = x+1 to MAXIMUM do
if amicable(pds, x, y) do
writef("%N, %N*N", x, y)
$)</lang>
 
{{out}}
<pre>220, 284
1184, 1210
2620, 2924
5020, 5564
6232, 6368
10744, 10856
12285, 14595
17296, 18416</pre>
 
=={{header|Befunge}}==
2,125

edits