Skip to content

Instantly share code, notes, and snippets.

@primus-lab
Last active December 31, 2019 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primus-lab/91683da3b45fda2d2dcbb24f9c713b24 to your computer and use it in GitHub Desktop.
Save primus-lab/91683da3b45fda2d2dcbb24f9c713b24 to your computer and use it in GitHub Desktop.
Conjectured primality test
# Author: Pedja
print(" ***** COP *****\n\n\n")
while True:
n=int(input("Enter a number : "))
def test(n):
s=0
for k in range(1,n):
s=s+pow(2**k-1,n-1,2**n-1)
return s%(2**n-1)==n
if n<3:
print("Number must be greater than two")
elif n==9:
print(str(n)+" is pseudoprime")
else:
if test(n):
print(str(n)+" is prime")
else:
print(str(n)+" is composite")
try_again = ""
# Loop until users opts to go again or quit
while not(try_again == "1") and not(try_again == "0"):
try_again = input("Press 1 to try again, 0 to exit. ")
if try_again in ["1", "0"]:
continue # a valid entry found
else:
print("Invalid input- Press 1 to try again, 0 to exit.")
# at this point, try_again must be "0" or "1"
if try_again == "0":
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment