|
|
A352374
|
|
a(1) = 1. For n >= 2, a(n) is the least nonprime not already in the sequence such that there is at least one prime between a(n-1) and a(n).
|
|
1
|
|
|
1, 4, 6, 8, 12, 9, 14, 10, 15, 18, 16, 20, 24, 21, 25, 22, 26, 30, 27, 32, 28, 33, 38, 34, 39, 35, 40, 36, 42, 44, 48, 45, 49, 46, 50, 54, 51, 55, 52, 56, 60, 57, 62, 58, 63, 68, 64, 69, 65, 70, 66, 72, 74, 80, 75, 81, 76, 82, 77, 84, 78, 85, 90, 86, 91, 87, 92, 88, 93, 98
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
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
|
|
|
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)
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
(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
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|