25 lines
590 B
Plaintext
25 lines
590 B
Plaintext
_maxNum = 10000
|
|
|
|
local fn IsPerfectNumber( n as long ) as BOOL
|
|
—————————————————————————————————————————————
|
|
if ( n < 2 ) then exit fn = NO
|
|
if ( n mod 2 == 1 ) then exit fn = NO
|
|
long sum = 1, q, i
|
|
for i = 2 to sqr(n)
|
|
if ( n mod i == 0 )
|
|
sum += i
|
|
q = n / i
|
|
if ( q > i ) then sum += q
|
|
end if
|
|
next
|
|
end fn = ( n == sum )
|
|
|
|
printf @"Perfect numbers in range %ld..%ld",2,_maxNum
|
|
|
|
long i
|
|
for i = 2 To _maxNum
|
|
if ( fn IsPerfectNumber(i) ) then print i
|
|
next
|
|
|
|
HandleEvents
|