Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inancgumus/2da2cfd048a0dc435410 to your computer and use it in GitHub Desktop.
Save inancgumus/2da2cfd048a0dc435410 to your computer and use it in GitHub Desktop.
'''
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