OFFSET
1,1
COMMENTS
2 cannot be on the list as all numbers are 0 or 1 mod 2, neither of which is prime.
There are three ways that the next term may be generated. If there is at least an odd prime < a(n) not on the list, a(n+1) is the smallest among them. Otherwise, if a(n)+2 is prime and not on the list, a(n+1) = a(n)+2. Otherwise, a(n+1) takes the form 2*k*a(n)+p with prime p. It is conjectured that k is always 1, which has been confirmed until n = 10000.
Because of the first generation step, this is a permutation of A065091.
LINKS
Hoang Nguyen, Table of n, a(n) for n = 1..10000
EXAMPLE
a(2) = 5 as 5 is prime and 5 mod 3 = 2 is prime.
a(4) = 17 as 17 is prime and 17 mod 7 = 3 is prime.
a(5) = 11 as 11 is prime and 11 mod 17 = 11 is prime.
MATHEMATICA
a[n_] := a[n] = Module[{ps = Array[a, n - 1], p = 5}, While[MemberQ[ps, p] || !PrimeQ[Mod[p, a[n - 1]]], p = NextPrime[p]]; p]; a[1] = 3; Array[a, 57] (* Amiram Eldar, May 21 2026 *)
PROG
(Julia)
using Primes
function a(n)
prime = [3]
print("3, ")
for _ in 1:n-1
num = 3
while true
num += 2
if isprime(num) && isprime(num % prime[end]) && !(num in prime)
push!(prime, num)
print("$num, ")
break
end
end
end
end
(Python)
from itertools import count, islice
from sympy import isprime, nextprime, sieve
def agen(): # generator of terms
an, nextp, seen = 3, 5, set()
while True:
yield an
seen.add(an)
while nextp in seen: nextp = nextprime(nextp)
if nextp < an: an = nextp
elif an+2 not in seen and isprime(an+2): an += 2
else: an = next(m for k in count(1) for p in sieve.primerange(3, an) if (m:=2*k*an+p) not in seen and isprime(m))
print(list(islice(agen(), 57))) # Michael S. Branicky, May 21 2026
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Hoang Nguyen, May 20 2026
STATUS
approved
