Skip to content

Instantly share code, notes, and snippets.

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