Advertisement
LucasSousa

testando primos

Mar 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. from math import sqrt
  2. from itertools import count, islice
  3.  
  4. import time as tempo
  5.  
  6.  
  7. def eh_primo(n):
  8.     return n > 1 and all(n % i for i in islice(count(2), int(sqrt(n) - 1)))
  9.  
  10.  
  11. n = 2000000
  12. inicio = int(round(tempo.time() * 1000))
  13. for i in range(0, n):
  14.     eh_primo(i)
  15.  
  16. tempoGasto = (int(round(tempo.time() * 1000))) - inicio
  17. print(
  18.     "Demorou " +
  19.     (str(tempoGasto)) +
  20.     "ms para checar se " +
  21.     (str(n)) +
  22.     " numeros sao primos."
  23. )
  24. #Demorou 29896ms para checar se 2000000 numeros sao primos.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement