Skip to content

Instantly share code, notes, and snippets.

@rmgimenez
Last active June 7, 2016 12:36
Show Gist options
  • Save rmgimenez/748e975bda0bca23126aa8d26ecc48f3 to your computer and use it in GitHub Desktop.
Save rmgimenez/748e975bda0bca23126aa8d26ecc48f3 to your computer and use it in GitHub Desktop.
Função que verifica se um número é primo em python
def is_prime(n):
if n == 2 or n == 3: return True
if n < 2 or n%2 == 0: return False
if n < 9: return True
if n%3 == 0: return False
r = int(n**0.5)
f = 5
while f <= r:
#print('\t',f)
if n%f == 0: return False
if n%(f+2) == 0: return False
f +=6
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment