Perfect numbers: Difference between revisions
Content added Content deleted
(→{{header|Smalltalk}}: + Tcl) |
m (formatting) |
||
Line 3: | Line 3: | ||
A number is perfect if the sum of its factors is equal to twice the number. An equivalent condition is that <tt>n</tt> is perfect if the sum of <tt>n</tt>'s factors that are less than <tt>n</tt> is equal to <tt>n</tt>. |
A number is perfect if the sum of its factors is equal to twice the number. An equivalent condition is that <tt>n</tt> is perfect if the sum of <tt>n</tt>'s factors that are less than <tt>n</tt> is equal to <tt>n</tt>. |
||
Note: The faster [[Lucas-Lehmer_test]] is used to find primes of the form |
Note: The faster [[Lucas-Lehmer_test]] is used to find primes of the form 2<sup>''n''</sup>-1, all ''known'' perfect numbers can derived from these primes using the formula (2<sup>''n''</sup> - 1) × 2<sup>''n'' - 1</sup>. It is not known if there are any odd perfect numbers. |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
Line 335: | Line 335: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
<lang tcl> |
<lang tcl>proc perfect n { |
||
set sum 0 |
|||
proc perfect n { |
|||
set |
for {set i 1} {$i <= $n} {incr i} { |
||
if {$n % $i == 0} {incr sum $i} |
|||
⚫ | |||
if {$n % $i == 0} {incr sum $i} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ |