Created
September 23, 2021 09:01
-
-
Save GiacomoPope/d11886f11d66847ccfd97cdfdcbc53e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.Util.number import isPrime | |
import math | |
import time | |
primes = [] | |
def find_primes(max_val): | |
N = math.ceil(math.sqrt(max_val)) | |
for n in range(0,N,2): | |
p = n**2 + 1 | |
if isPrime(p): | |
primes.append((p,n)) | |
return primes | |
max_value = 100_000_000 | |
t_start = time.time() | |
primes = find_primes(max_value) | |
t_end = time.time() | |
print(f"Time taken: {round(t_end - t_start, 5)}s") | |
p,n = primes[-1] | |
print(f"Max value found: {p} = {n}^2 + 1") | |
print(f"Total primes for n <= {max_value}: {len(primes)}") | |
# Time taken: 0.70909s | |
# Max value found: 99800101 = 9990^2 + 1 | |
# Total primes n^2 + 1 <= 100000000: 840 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment