Python  1.0
Functions
_04c_perfect Namespace Reference

Looking for perfect numbers. More...

Functions

def is_perfect (num)
 Checks whether a given number is perfect. More...
 
def find_perfect (n)
 Finds the first n perfect numbers. More...
 
def main ()
 Main function for testing. More...
 

Detailed Description

Looking for perfect numbers.

Many ancient cultures were concerned with the relationship of a number with the sum of its divisors, often giving mystic interpretations. Here we are concerned only with one such relationship:

For example, 6 is the first perfect number because 6=1+2+3. The next is 28=1+2+4+7+14. The next two are 496 and 8128. These four were all known before the time of Christ.

Looking at these numbers in the following partially factored form:

\[2 \times 3, 4 \times 7, 16 \times 31, 64 \times 127,\]

it is possible to notice that they all have the same form: \(2^{n-1}(2^{n}-1)\) (for n = 2, 3, 5, and 7, respectively). Furthermore, in each case, \(2^{n}-1\) is a Mersenne prime.

Author
Paulo Roma
Since
28/12/2008
See also
http://mathworld.wolfram.com/PerfectNumber.html
http://en.wikipedia.org/wiki/Perfect_number
http://www.archive.org/details/lecture12090
http://www.mersenne.org/
http://primes.utm.edu/mersenne/

Function Documentation

◆ find_perfect()

def _04c_perfect.find_perfect (   n)

Finds the first n perfect numbers.

Euclid (300 BC) proved that whenever n is prime AND \(2^n - 1\) is also prime, then \(2^{(n-1)}(2^{n} - 1)\) is perfect, and Euler (1707-1783) showed that all even perfect numbers are of the form, \(2^{(n-1)}(2^{n}-1)\).

An odd perfect number has never been found...

Dickson: Introduction to The Theory of Numbers, page 5, ex. 8

E.g., 6 = 2 * 3, 28 = 4 * 7, 496 = 16 * 31, 8128 = 64 * 127

Parameters
nnumber of perfect numbers to be found.
Returns
list with the first n perfect numbers.

Referenced by main().

◆ is_perfect()

def _04c_perfect.is_perfect (   num)

Checks whether a given number is perfect.

A perfect number is defined as an integer which is the sum of its proper positive divisors, that is, the sum of the positive divisors not including the number.

e.g. 6, 28, 496, 8128, 33550336, 8589869056, 137438691328, 2305843008139952128

Parameters
numgiven number.
Returns
True if num is perfect, plus the list of its factors, and False otherwise.

Referenced by main().

◆ main()

def _04c_perfect.main ( )

Main function for testing.

References find_perfect(), _01d_dec2bin.input, and is_perfect().