I wrote this simple python 3.7 code for verifying prime numbers however I'm seeing bottlenecks with numbers over 10 digits long. I know that's weak, but I think there is hope for this piece of code with your help.
Is it possible to speed up this program to make it run super fast?
The program states False for composites and True for prime numbers. For instance this number (1235468711) takes 16 seconds to report False which equals a composite number.
By the way (a) has to remain in that state for the code to work.
I have tried compact mapping and no speed enhancement was found.
Here is the code:
p = int(input('Enter a prime number and if True its prime: '))
def prime(*kwargs):
for i in kwargs:
yield i
k = (2 * p)
a = prime((2 ** (p + 1) - 1) % k)
for i in a:
if i == 3:
print(i is not False, "| If True number is prime!")
else:
print(False, "| If False number is not prime!")