Skip to content

Instantly share code, notes, and snippets.

@davidsonbrsilva
Created March 31, 2019 23:36
Show Gist options
  • Save davidsonbrsilva/ac8ab9e3253b89a584bc72055794f939 to your computer and use it in GitHub Desktop.
Save davidsonbrsilva/ac8ab9e3253b89a584bc72055794f939 to your computer and use it in GitHub Desktop.
Implementação de testes de primalidade: optimal
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