Last active
July 24, 2023 02:05
-
-
Save klenne/62f245ea8bae07efaf1b69c0321c2310 to your computer and use it in GitHub Desktop.
implementando fórmula de Isidoro de Sevilha
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
""" | |
Fórmula Isidoro para descobrir números perfeitos | |
Author: Klenne | |
Faculdade das Américas - FAM | |
""" | |
import math | |
tamanho = 32 | |
def numero_primo(n): # ' Para verificar se número é primo | |
if n <= 3: | |
return True | |
k = math.sqrt(n) | |
count = 3 | |
while count <= k: | |
if n % count == 0: | |
return False | |
count += 2 | |
return True | |
for numero in range(2, tamanho): | |
potencia = ((2 ** numero) - 1) # ' (2^numero)- 1 | |
primo = numero_primo(potencia) | |
if primo: # ' se (2^numero)-1 for primo | |
print(potencia * (2 ** (numero - 1)), " é perfeito !!!") | |
# 'então (2^numero)- 1 * 2^(numero-1) é um número perfeito | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment