Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt
- from itertools import count, islice
- import time as tempo
- def eh_primo(n):
- return n > 1 and all(n % i for i in islice(count(2), int(sqrt(n) - 1)))
- n = 2000000
- inicio = int(round(tempo.time() * 1000))
- for i in range(0, n):
- eh_primo(i)
- tempoGasto = (int(round(tempo.time() * 1000))) - inicio
- print(
- "Demorou " +
- (str(tempoGasto)) +
- "ms para checar se " +
- (str(n)) +
- " numeros sao primos."
- )
- #Demorou 29896ms para checar se 2000000 numeros sao primos.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement