Perfect numbers: Difference between revisions

Content added Content deleted
(Remove unnecessary iteration and logically redundant test (if [sum == 2 * num] then [sum - num == num] for all positive num anyway).)
m (Added wp ref and fixed definition - see discussion)
Line 1:
{{task|Discrete math}}Write a function which says whether a number is perfect.
 
[[wp:Perfect_numbers|A perfect number]] is perfecta ifpositive integer that is the sum of its factorsproper is equalpositive todivisors twiceexcluding the number itself. AnEquivalently, equivalenta conditionperfect number is thata <tt>n</tt>number isthat perfectis ifhalf the sum of <tt>n</tt>'sall factorsof thatits are less than <tt>n</tt> ispositive equaldivisors to(including <tt>n</tt>itself).
 
Note: The faster [[Lucas-Lehmer test]] is used to find primes of the form 2<sup>''n''</sup>-1, all ''known'' perfect numbers can be 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.