Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/prime_test.py #59

Closed
arpitjain305 opened this issue May 9, 2017 · 4 comments
Closed

math/prime_test.py #59

arpitjain305 opened this issue May 9, 2017 · 4 comments
Labels

Comments

@arpitjain305
Copy link

the prime_test function returns true for 35, while 35 is not a prime.

@keon keon added the bug label May 9, 2017
@ankit167
Copy link
Collaborator

ankit167 commented May 9, 2017

Also returns true for 25

@Aluriak
Copy link

Aluriak commented May 9, 2017

Well, by looking quickly to the source, it is obvious that the algorithm is false. The most basic fix is to add n % 5 == 0 in line 11, but i bet i would not be sufficient.

The following code seems to work better:

if n <= 1: return False
for i in range(2, 1 + int(math.sqrt(n))):
    if n % i == 0: return False
return True

@ankit167
Copy link
Collaborator

@Aluriak could you please push the fix.

@mathagician
Copy link

This has been fixed and pull request has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants