Commit f0dab743 authored by Taddeus Kroes's avatar Taddeus Kroes

41: Improved is_prime function.

parent 353fb7ef
from math import sqrt, ceil
from itertools import permutations
def is_prime(n):
if n == 2:
return True
if not n % 2:
if n < 2 or not n & 1:
return False
for i in xrange(3, int(ceil(sqrt(n))) + 1 + 1, 2):
for i in xrange(3, int(n ** .5) + 1, 2):
if not divmod(n, i)[1]:
return False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment