Amicable pairs: Difference between revisions

Content added Content deleted
m (Automated syntax highlighting fixup (second round - minor fixes))
No edit summary
Line 5,593: Line 5,593:
18416 17296
18416 17296
</pre>
</pre>

=={{header|S-BASIC}}==
<lang BASIC>
$lines

$constant search_limit = 20000

rem - return p mod q
function mod(p, q = integer) = integer
end = p - q * (p / q)

rem - return sum of the proper divisors of n
function sumf(n = integer) = integer
var f1, f2, sum = integer
sum = 1
f1 = 2
while (f1 * f1) <= n do
beginexit
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
end = sum

rem - main program begins here
var a, b, count = integer
print "Searching up to"; search_limit; " for amicable pairs:"
count = 0
for a = 2 to search_limit do
b = sumf(a)
if b > a then
if a = sumf(b) then
begin
print using "##### #####"; a; b
count = count + 1
end
next a
print count; " pairs were found"

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
8 pairs were found
</pre>



=={{header|Scala}}==
=={{header|Scala}}==