Oct-27-2017, 06:26 PM
(This post was last modified: Oct-27-2017, 06:26 PM by PythonLamer.)
Looking for a way to optimize this to have it run a bit faster:
Does anyone have any suggestions?
#!python3 def isPrime(num): if num < 2: return False if num == 2: return True else: for div in range(2,int(num / 2)): if num % div == 0: return False return True for i in range(1000000000000000,9999999999999999): if isPrime(i): i = (i * 2) + 1 if isPrime(i): print(int((i - 1) / 2)) breakSo a quick background on the code. It tests for safe prime numbers, where p = (p * 2) +1, and where the original p is prime and the calculated p is also prime. An example is 5, because 5 is a prime number and 5*2+1=11, which is also prime.
Does anyone have any suggestions?