Created
September 24, 2018 18:48
-
-
Save acwoss/25f49df1349d75f57b1f5cab5f6abf45 to your computer and use it in GitHub Desktop.
FearlessMagnificentCharactercode created by acwoss - https://repl.it/@acwoss/FearlessMagnificentCharactercode
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
code = ''' | |
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(1e999999999999999999999): | |
print(i) | |
''' | |
import timeit | |
print(timeit.timeit(code, number=1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment