Skip to content

Commit

Permalink
Fix | keon#58 | Correct the logic of Prime testing function in math/t…
Browse files Browse the repository at this point in the history
…est_prime.py in an efficient way
  • Loading branch information
harshtheworkman committed May 14, 2017
1 parent 76c50d6 commit a4ca73b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions math/prime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ def prime_test(n):
return True
if n%2==0 or n%3==0:
return False
j = 6
while(j*j < n):
if n%(j-1)==0 or n%(j+1)==0:

j = 5
while(j*j <= n):
if n%(j)==0 or n%(j+2)==0:
return False
j += 6
return True

0 comments on commit a4ca73b

Please sign in to comment.