login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
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

%I #32 Apr 16 2022 10:26:38

%S 1,4,6,8,12,9,14,10,15,18,16,20,24,21,25,22,26,30,27,32,28,33,38,34,

%T 39,35,40,36,42,44,48,45,49,46,50,54,51,55,52,56,60,57,62,58,63,68,64,

%U 69,65,70,66,72,74,80,75,81,76,82,77,84,78,85,90,86,91,87,92,88,93,98

%N 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).

%C Inspired by Recamán's sequence A005132.

%C This is a permutation of the nonprime numbers.

%C Is the number of primes that may fall between any two consecutive terms bounded?

%H Michael De Vlieger, <a href="/A352374/b352374.txt">Table of n, a(n) for n = 1..10000</a>

%e 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.

%e Then, a(6) = 9 (even though 9 is less than 12), as prime 11 falls between it and 12.

%t 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 *)

%o (MATLAB)

%o function [ a ] = A352374( max_n )

%o a(1) = 1;

%o for n=2:max_n

%o k = 2;

%o while isprime(k) ...

%o ||~isempty(find(a==k, 1)) ...

%o ||isempty(find(isprime(min(k,a(end)):max(k,a(end))), 1))

%o k = k+1;

%o end

%o a(n) = k;

%o end

%o end % _Thomas Scheuerle_, Mar 14 2022

%o (Python)

%o from itertools import islice

%o from sympy import isprime, nextprime

%o def primebetween(k, m): return nextprime(min(k, m)) < max(k, m)

%o def agen(): # generator of terms

%o lastan, an, aset, leastout = None, 1, set(), 2

%o while True:

%o yield an

%o aset.add(an)

%o lastan, an = an, leastout

%o while an in aset or isprime(an) or not primebetween(lastan, an):

%o an += 1

%o while leastout in aset: leastout += 1

%o print(list(islice(agen(), 70))) # _Michael S. Branicky_, Mar 14 2022

%Y Cf. A005132.

%K nonn

%O 1,2

%A _Tamas Sandor Nagy_, Mar 14 2022

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified August 20 09:14 EDT 2024. Contains 375325 sequences. (Running on oeis4.)