Skip to content

Commit a4ca73b

Browse files
Fix | keon#58 | Correct the logic of Prime testing function in math/test_prime.py in an efficient way
1 parent 76c50d6 commit a4ca73b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

math/prime_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ def prime_test(n):
1010
return True
1111
if n%2==0 or n%3==0:
1212
return False
13-
j = 6
14-
while(j*j < n):
15-
if n%(j-1)==0 or n%(j+1)==0:
13+
14+
j = 5
15+
while(j*j <= n):
16+
if n%(j)==0 or n%(j+2)==0:
1617
return False
1718
j += 6
1819
return True

0 commit comments

Comments
 (0)