Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Perfect-numbers/S-BASIC/perfect-numbers.basic
Normal file
39
Task/Perfect-numbers/S-BASIC/perfect-numbers.basic
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
$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
|
||||
Loading…
Add table
Add a link
Reference in a new issue