OFFSET
1,2
COMMENTS
Inspired by Recamán's sequence A005132.
This is a permutation of the nonprime numbers.
Is the number of primes that may fall between any two consecutive terms bounded?
LINKS
Michael De Vlieger, Table of n, a(n) for n = 1..10000
EXAMPLE
Following a(4) = 8, a(5) cannot be 9 or 10 since no prime number falls between 8 and these. Therefore, a(5) = 12, as it is nonprime and prime 11 falls between it and 8.
Then, a(6) = 9 (even though 9 is less than 12), as prime 11 falls between it and 12.
MATHEMATICA
nn = 120; c[_] = 0; a[1] = c[1] = u = 1; m = 0; While[c[u] > 0, u++]; Do[k = u; While[Set[p, PrimePi[k]]; Nand[c[k] == 0, CompositeQ[k], Abs[p - m] > 0], k++]; If[k == u, While[c[u] > 0, u++]]; Set[{a[i], c[k], m}, {k, i, p}], {i, 2, nn}]; Array[a, nn] (* Michael De Vlieger, Apr 16 2022 *)
PROG
(MATLAB)
function [ a ] = A352374( max_n )
a(1) = 1;
for n=2:max_n
k = 2;
while isprime(k) ...
||~isempty(find(a==k, 1)) ...
||isempty(find(isprime(min(k, a(end)):max(k, a(end))), 1))
k = k+1;
end
a(n) = k;
end
end % Thomas Scheuerle, Mar 14 2022
(Python)
from itertools import islice
from sympy import isprime, nextprime
def primebetween(k, m): return nextprime(min(k, m)) < max(k, m)
def agen(): # generator of terms
lastan, an, aset, leastout = None, 1, set(), 2
while True:
yield an
aset.add(an)
lastan, an = an, leastout
while an in aset or isprime(an) or not primebetween(lastan, an):
an += 1
while leastout in aset: leastout += 1
print(list(islice(agen(), 70))) # Michael S. Branicky, Mar 14 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Tamas Sandor Nagy, Mar 14 2022
STATUS
approved