Created
March 31, 2019 23:36
-
-
Save davidsonbrsilva/ac8ab9e3253b89a584bc72055794f939 to your computer and use it in GitHub Desktop.
Implementação de testes de primalidade: optimal
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
def optimal(number): | |
if number >= 2: | |
# Calcula a raiz quadrada de number | |
sqrt_n = int(math.sqrt(number) + 1) | |
for index in range(2, sqrt_n): | |
# Se houver algum divisor entre 1 (exclusive) e a raiz quadrada de number, number não é primo. | |
if number % index == 0: | |
return False | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment