Last active
June 7, 2016 12:36
-
-
Save rmgimenez/748e975bda0bca23126aa8d26ecc48f3 to your computer and use it in GitHub Desktop.
Função que verifica se um número é primo em python
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 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