# Python program for OEIS A067024 # after translation of Daniel Suteu's PARI for A067024 # by Michael S. Branicky, Feb 06 2023 # A067024 Smallest prime p such that p+2 has n distinct prime factors. 7 data = [2, 13, 103, 1153, 15013, 255253, 4849843, 111546433, 4360010653, 100280245063, 5245694198743, 152125131763603, 7149881192889433, 421842990380476663, 16294579238595022363] from sympy import primorial, primerange, integer_nthroot, isprime def cond(n): return isprime(n-2) def omega_cond(A, B, n): A = max(A, primorial(n)) def f(m, p, j): lst = [] for q in primerange(p, integer_nthroot(B//m, j)[0]+2): v = m*q #if q == 5 and v%2 == 0: # continue while v <= B: if j == 1: if v >= A and cond(v): lst.append(v) elif v*(q+1) <= B: lst += f(v, q+1, j-1) v *= q return lst return sorted(f(1, 3, n)) def a(n): if n == 1: return 2 x = primorial(n) y = 3*x while True: v = omega_cond(x, y, n) if len(v) > 0: return v[0]-2 x = y+1 y = 3*x print([a(n) for n in range(1, 3)]) from time import time time0 = time() alst = [] for n in range(1, 10001): an = a(n) alst.append(an) print(n, an, len(str(an)), len(str(alst))-2, time()-time0) if len(str(alst)) < 280: print(" ", alst) print(" ", data) with open('b067024.txt', 'a') as bfile: bfile.write(f"{n} {an}\n")