Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- debian :: ~ % python
- Python 2.7.9 (default, Mar 1 2015, 12:57:24)
- [GCC 4.9.2] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> from math import sqrt
- >>> def isPrime(x):
- ... # Naive algorithm
- ... if x<=1 : return False
- ... if x==2: return True
- ... if x%2==0: return False
- ... for i in xrange( 3, int(sqrt(x))+1, 2 ):
- ... if x%i==0:
- ... return False
- ... return True
- ...
- >>> isPrime( 5) and isPrime(11)
- True
- >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement