Created
September 24, 2018 18:36
-
-
Save acwoss/862f97a6cc5887a553aa7431a1556442 to your computer and use it in GitHub Desktop.
UnsungQueasyMap created by acwoss - https://repl.it/@acwoss/UnsungQueasyMap
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
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