Perfect numbers: Difference between revisions
Content added Content deleted
(add RPL) |
(FutureBasic solution added) |
||
Line 1,758: | Line 1,758: | ||
(6, 28, 496) |
(6, 28, 496) |
||
</pre> |
</pre> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
_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 |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Perfect numbers in range 2..10000 |
|||
6 |
|||
28 |
|||
496 |
|||
8128 |
|||
</pre> |
|||
=={{header|GAP}}== |
=={{header|GAP}}== |