Skip to content

Instantly share code, notes, and snippets.

@acwoss
Created September 24, 2018 18:36
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 acwoss/862f97a6cc5887a553aa7431a1556442 to your computer and use it in GitHub Desktop.
Save acwoss/862f97a6cc5887a553aa7431a1556442 to your computer and use it in GitHub Desktop.
UnsungQueasyMap created by acwoss - https://repl.it/@acwoss/UnsungQueasyMap
def perfect_numbers(N):
def sieve_of_eratosthene(N):
A = [True] * (N+1)
A[0] = A[1] = False
for value, prime in enumerate(A):
if prime:
yield value
for i in range(value**2, N+1, value):
A[i] = False
primes = sieve_of_eratosthene(500)
while True:
p = next(primes)
perfect_number = 2**(p-1) * (2**p - 1)
if perfect_number > N:
break
yield perfect_number
for i in perfect_numbers(500):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment