import time
def is_prime(number):
i = 3
while i**2 <= number:
if number % i == 0:
return False
i += 2
return True
def lucas_lehmer(p):
s = 4
M = 2**p - 1
for _ in range(p - 2):
s = ((s * s) - 2) % M
return s == 0
def mersenne_primes():
p = 3
while True:
if is_prime(p) and lucas_lehmer(p):
yield (p, 2**p - 1)
p += 2
start = time.time()
numbers = mersenne_primes()
for _ in range(10):
p, mersenne = next(numbers)
perfect = 2**(p-1) * mersenne
print(perfect)
print('Executado em ' + str(time.time() - start) + 's')
aW1wb3J0IHRpbWUKCmRlZiBpc19wcmltZShudW1iZXIpOgogICAgaSA9IDMKICAgIHdoaWxlIGkqKjIgPD0gbnVtYmVyOgogICAgICAgIGlmIG51bWJlciAlIGkgPT0gMDoKICAgICAgICAgICAgcmV0dXJuIEZhbHNlCiAgICAgICAgaSArPSAyCiAgICByZXR1cm4gVHJ1ZQoKZGVmIGx1Y2FzX2xlaG1lcihwKToKICAgIHMgPSA0CiAgICBNID0gMioqcCAtIDEKCiAgICBmb3IgXyBpbiByYW5nZShwIC0gMik6CiAgICAgICAgcyA9ICgocyAqIHMpIC0gMikgJSBNCiAgICByZXR1cm4gcyA9PSAwCgpkZWYgbWVyc2VubmVfcHJpbWVzKCk6CiAgICBwID0gMwogICAgd2hpbGUgVHJ1ZToKICAgICAgICBpZiBpc19wcmltZShwKSBhbmQgbHVjYXNfbGVobWVyKHApOgogICAgICAgICAgICB5aWVsZCAocCwgMioqcCAtIDEpCiAgICAgICAgcCArPSAyCgpzdGFydCA9IHRpbWUudGltZSgpCm51bWJlcnMgPSBtZXJzZW5uZV9wcmltZXMoKQoKZm9yIF8gaW4gcmFuZ2UoMTApOgogICAgcCwgbWVyc2VubmUgPSBuZXh0KG51bWJlcnMpCiAgICBwZXJmZWN0ID0gMioqKHAtMSkgKiBtZXJzZW5uZQogICAgcHJpbnQocGVyZmVjdCkKCnByaW50KCdFeGVjdXRhZG8gZW0gJyArIHN0cih0aW1lLnRpbWUoKSAtIHN0YXJ0KSArICdzJyk=