Skip to content

Instantly share code, notes, and snippets.

@joehakimrahme
Created July 4, 2012 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehakimrahme/3048036 to your computer and use it in GitHub Desktop.
Save joehakimrahme/3048036 to your computer and use it in GitHub Desktop.
isprime - up to sqrt()
import math.sqrt as sqrt
def prime2(n):
if n <= 1:
return False
# The sqrt is turned into an int() because of the
# deprecation warning I got for passing a float as argument
# to xrange()
for i in xrange(2, int(sqrt(n))):
if n % i == 0:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment