Jump to content

Perfect numbers: Difference between revisions

Updated to work with Nim 1.4. Changed indentation to conform to guidelines. Corrected the algorithm which computed an incorrect sum for square numbers.
No edit summary
(Updated to work with Nim 1.4. Changed indentation to conform to guidelines. Corrected the algorithm which computed an incorrect sum for square numbers.)
Line 2,354:
 
proc isPerfect(n: int): bool =
var sum: int = 1
for id in 2 .. <int(n.toFloat.sqrt+1).toInt:
if n mod id == 0:
inc sum, += (i + n div i)d
return (n let q == sum)n div d
if q != d: inc sum, q
result = n == sum
 
for in in 2..10_000:
if n.isPerfect(i):
echo echo(i)n</lang>
 
{{out}}
<pre>6
28
496
8128</pre>
 
=={{header|Objeck}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.