Created
January 18, 2015 21:09
-
-
Save inancgumus/2da2cfd048a0dc435410 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Euclide's Theorem 3.3 from Book IX | |
Finding perfect numbers. | |
Perfect number is a number that is the sum of its proper divisors. | |
Examples: | |
6 = 1 + 2 + 3 | |
28 = 1 + 2 + 4 + 7 + 14 | |
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 | |
''' | |
n = 1 # enter a number here to find a perfect number | |
p = sum(map(lambda n: 2 ** n, range(0, n + 1))) | |
q = (2 ** n) * p if is_prime(p) else 0 | |
if q != 0: | |
print q, 'is perfect!' | |
else: | |
print q, 'is NOT perfect...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment