Skip to content

Instantly share code, notes, and snippets.

@en0
Last active November 10, 2018 16:31
Show Gist options
  • Save en0/2e71dba8d186cc541d96b119cd3436b0 to your computer and use it in GitHub Desktop.
Save en0/2e71dba8d186cc541d96b119cd3436b0 to your computer and use it in GitHub Desktop.
O(1) Prime test
def is_prime(p):
"""Not Perfect - Do not use."""
if p > 2:
return ((2**(p-1)) % p) == 1
return p == 2
@en0
Copy link
Author

en0 commented Nov 10, 2018

This is prone to false positives. e.g. 341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment