40 lines
730 B
Plaintext
40 lines
730 B
Plaintext
$lines
|
|
|
|
rem - return p mod q
|
|
function mod(p, q = integer) = integer
|
|
end = p - q * (p/q)
|
|
|
|
rem - return true if n is perfect, otherwise false
|
|
function isperfect(n = integer) = integer
|
|
var sum, f1, f2 = integer
|
|
sum = 1
|
|
f1 = 2
|
|
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
|
|
end = (sum = n)
|
|
|
|
rem - exercise the function
|
|
|
|
var k, found = integer
|
|
|
|
print "Searching up to"; search_limit; " for perfect numbers ..."
|
|
found = 0
|
|
for k = 2 to search_limit
|
|
if isperfect(k) then
|
|
begin
|
|
print k
|
|
found = found + 1
|
|
end
|
|
next k
|
|
print found; " were found"
|
|
|
|
end
|