-
Notifications
You must be signed in to change notification settings - Fork 0
/
A354426.py
34 lines (29 loc) · 903 Bytes
/
A354426.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env python3
from labmath import *
from multiprocessing import Pool
def test(p):
p2p1 = p*p + p + 1
p2p1_primes = set()
for q in primefac(p2p1):
if q in p2p1_primes: continue
p2p1_primes.add(q)
q2q1 = q*q + q + 1
q2q1_primes = set()
for r in primefac(q2q1):
if r in q2q1_primes: continue
q2q1_primes.add(r)
if (r+1) % p == 0: return (p, True)
return (p, False)
while True:
threads = input("Enter the number of threads to use: ")
if threads.isdecimal():
threads = int(threads)
if threads > 0: break
print("You must enter a positive integer.")
with Pool(threads) as P:
n = 0
for (p, flag) in P.imap(test, primegen(), chunksize=100):
print('\b'*42, p, end='', flush=True)
if flag:
n += 1
print('\b'*42, n, ' ', p, sep='')