Amicable pairs: Difference between revisions

Content deleted Content added
m added a category.
Ssmitch45 (talk | contribs)
No edit summary
Line 297:
12285, 14595
17296, 18416
</pre>
 
=={{header|ALGOL-60}}==
{{works with|A60}}
<lang algol60>
begin
comment - return p mod q;
integer procedure mod(p, q);
value p, q; integer p, q;
begin
mod := p - q * entier(p / q);
end;
 
comment - return the sum of the proper divisors of n;
integer procedure sumf(n);
value n; integer n;
begin
integer sum, f1, f2;
sum := 1;
f1 := 2;
for f1 := f1 while (f1 * f1) < n do
begin
if mod(n, f1) = 0 then
begin
sum := sum + f1;
f2 := n / f1;
if f2 > f1 then sum := sum + f2;
end;
f1 := f1 + 1;
end;
sumf := sum;
end;
 
comment - main program begins here;
integer a, b, c;
outstring(1,"Searching up to 10000 for amicable pairs\n");
for a := 2 step 1 until 10000 do
begin
b := sumf(a);
if b > a then
begin
c := sumf(b);
if a = c then
begin
outinteger(1,a);
outinteger(1,b);
outstring(1,"\n");
end;
end;
end;
outstring(1,"That\'s all. Goodbye.");
 
end
</lang>
{{out}}
<pre>
Searching up to 20000 for amicable pairs
220 284
1184 1210
2620 2924
5020 5564
6232 6368
10744 10856
12285 14595
17296 18416
That's all. Goodbye.
</pre>
 
=={{header|ALGOL 68}}==
<lang algol68># resturnsreturns the sum of the proper divisors of n #
# if n = 1, 0 or -1, we return 0 #
PROC sum proper divisors = ( INT n )INT: