import math, time
def sieve_of_eratosthene(N):
# Cria-se uma lista referente a todos os inteiros entre 0 e N:
A = [True] * (N+1)
# Define os números 0 e 1 como não primos:
A[0] = A[1] = False
# Percorra a lista até encontrar o primeiro número primo:
for value, prime in enumerate(A):
# O número é primo?
if prime:
# Retorna o número primo:
yield value
# Remova da lista todos os múltiplos do número enontrado:
for i in range(value**2, N+1, value):
A[i] = False
start = time.time()
# Percorre a lista de números primos menores que N:
for prime in sieve_of_eratosthene(500):
# Calcula o valor de n que define o Pn:
n = math.log2(prime+1)
# Verifica se n é inteiro, sendo um primo de Mersenne:
is_mersenne = n.is_integer()
# Se for um primo de Mersenne, calcula o número perfeito:
if is_mersenne:
print(2**(n-1) * prime)
print('Tempo de execução: ' + str(time.time() - start) + 's')
aW1wb3J0IG1hdGgsIHRpbWUKCmRlZiBzaWV2ZV9vZl9lcmF0b3N0aGVuZShOKToKCiAgICAjIENyaWEtc2UgdW1hIGxpc3RhIHJlZmVyZW50ZSBhIHRvZG9zIG9zIGludGVpcm9zIGVudHJlIDAgZSBOOgogICAgQSA9IFtUcnVlXSAqIChOKzEpCgogICAgIyBEZWZpbmUgb3MgbsO6bWVyb3MgMCBlIDEgY29tbyBuw6NvIHByaW1vczoKICAgIEFbMF0gPSBBWzFdID0gRmFsc2UKCiAgICAjIFBlcmNvcnJhIGEgbGlzdGEgYXTDqSBlbmNvbnRyYXIgbyBwcmltZWlybyBuw7ptZXJvIHByaW1vOgogICAgZm9yIHZhbHVlLCBwcmltZSBpbiBlbnVtZXJhdGUoQSk6CgogICAgICAgICMgTyBuw7ptZXJvIMOpIHByaW1vPwogICAgICAgIGlmIHByaW1lOgoKICAgICAgICAgICAgIyBSZXRvcm5hIG8gbsO6bWVybyBwcmltbzoKICAgICAgICAgICAgeWllbGQgdmFsdWUKCiAgICAgICAgICAgICMgUmVtb3ZhIGRhIGxpc3RhIHRvZG9zIG9zIG3Dumx0aXBsb3MgZG8gbsO6bWVybyBlbm9udHJhZG86CiAgICAgICAg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