RosettaCodeData/Task/Amicable-pairs/Draco/amicable-pairs.draco
2023-07-01 13:44:08 -04:00

28 lines
672 B
Text

/* Fill a given array such that for each N,
* P[n] is the sum of proper divisors of N */
proc nonrec propdivs([*] word p) void:
word i, j, max;
max := dim(p,1)-1;
for i from 0 upto max do p[i] := 0 od;
for i from 1 upto max/2 do
for j from i*2 by i upto max do
p[j] := p[j] + i
od
od
corp
/* Find all amicable pairs between 0 and 20,000 */
proc nonrec main() void:
word MAX = 20000;
word i, j;
[MAX] word p;
propdivs(p);
for i from 1 upto MAX-1 do
for j from i+1 upto MAX-1 do
if p[i]=j and p[j]=i then
writeln(i:5, ", ", j:5)
fi
od
od
corp