Advertisement
Guest User

Untitled

a guest
Oct 15th, 2015
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. debian :: ~ % python
  2. Python 2.7.9 (default, Mar 1 2015, 12:57:24)
  3. [GCC 4.9.2] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> from math import sqrt
  6. >>> def isPrime(x):
  7. ... # Naive algorithm
  8. ... if x<=1 : return False
  9. ... if x==2: return True
  10. ... if x%2==0: return False
  11. ... for i in xrange( 3, int(sqrt(x))+1, 2 ):
  12. ... if x%i==0:
  13. ... return False
  14. ... return True
  15. ...
  16. >>> isPrime( 5) and isPrime(11)
  17. True
  18. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement