Last active
January 10, 2023 16:17
-
-
Save typicalTYLER/666cfe4e6d329555ad56ea225defbf22 to your computer and use it in GitHub Desktop.
A213334.py
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
import time | |
import gmpy2 | |
import os | |
import cProfile | |
from multiprocessing import Pool | |
import primesieve | |
def test(p): | |
p2 = pow(gmpy2.mpz(p), 2) | |
if not p2.is_congruent(1, 9240): | |
return False | |
for k in range(1, 9): | |
if not gmpy2.is_prime((k+1)*p2-k, 1): | |
return False | |
for k in range(1, 9): | |
if not gmpy2.is_prime((k+1)*p2-k, 25): | |
return False | |
return p | |
def main(): | |
filename = os.path.basename(os.getcwd()) + ".dat" | |
filename_result = os.path.basename(os.getcwd()) + "result.dat" | |
try: | |
with open(filename) as startFile: | |
startprime = int(startFile.read()) | |
except FileNotFoundError: | |
startprime = 75902670689 | |
currentprime = startprime | |
primeit = primesieve.Iterator() | |
primeit.skipto(currentprime-1) | |
num_threads = 4 | |
batch_size = 100000000 | |
num_chunks = 1000 | |
chunk_size = batch_size // num_chunks | |
start = time.time()-0.00000001 | |
count = 0 | |
with Pool(num_threads) as p: | |
while True: | |
count += batch_size | |
currentprime = primeit.next_prime() | |
primeit.skipto(currentprime-1) | |
chunk_iterator = p.imap_unordered(test, (primeit.next_prime() for _ in range(batch_size)), chunk_size) | |
for result in chunk_iterator: | |
if result: | |
print("M = {}".format(result)) | |
exit(0) | |
with open(filename_result, 'a') as resultFile: | |
resultFile.write(str(result) + "\n") | |
if count % 10000000 == 0: | |
now = time.time() | |
print("m/s: {}, Current m: {}".format(int(count//(now - start)), currentprime)) | |
with open(filename, 'w') as startFile: | |
startFile.write(str(currentprime)) | |
if __name__ == '__main__': | |
# cProfile.run("main()") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment