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!)
A255004 Lexicographically earliest permutation of positive integers such that a(a(n)+a(n+1)) is prime for all n. 4

%I #18 Mar 22 2019 05:25:43

%S 1,2,3,4,5,6,7,8,11,9,13,10,17,12,19,14,15,16,23,29,18,31,37,20,21,22,

%T 41,24,43,25,47,26,53,27,28,30,32,33,59,34,61,35,67,36,38,39,71,40,73,

%U 42,44,79,45,46,83,48,89,97,49,50,51,101,103,52,107,54

%N Lexicographically earliest permutation of positive integers such that a(a(n)+a(n+1)) is prime for all n.

%C This is the sequence V defined in the Comments on A255003.

%H Alois P. Heinz, <a href="/A255004/b255004.txt">Table of n, a(n) for n = 1..10000</a>

%p N:= 100: # to get a(n) for n <= N

%p maxprime:= 2:

%p maxa:= 2:

%p a[1]:= 1:

%p a[2]:= 2:

%p needprime:= {3}:

%p for n from 3 to N do

%p if member(n,needprime) then

%p a[n]:= nextprime(maxprime);

%p maxprime:= a[n];

%p else

%p if isprime(maxa+1) and maxa+1<= maxprime then a[n]:= maxa+2

%p else a[n]:= maxa+1

%p fi;

%p maxa:= a[n];

%p fi;

%p needprime:= needprime union {a[n-1]+a[n]};

%p od:

%p seq(a[n],n=1..N); # _Robert Israel_, Mar 26 2015

%t M = 100;

%t maxprime = 2; maxa = 2; a[1] = 1; a[2] = 2; needprime = {3}; For[n = 3, n <= M, n++, If[MemberQ[needprime, n], a[n] = NextPrime[maxprime]; maxprime = a[n], If[PrimeQ[maxa+1] && maxa+1 <= maxprime, a[n] = maxa+2, a[n] = maxa+1]; maxa = a[n]]; needprime = needprime ~Union~ {a[n-1] + a[n]}];

%t Array[a, M] (* _Jean-François Alcover_, Mar 22 2019, after _Robert Israel_ *)

%o (PARI) {a=vector(100,i,1); u=[1]/* used numbers beyond u[1] */; for(n=2,#a, if( a[n] < 0, a[n]=u[1]; while(setsearch(u,a[n]++)||!isprime(a[n]),), a[n]=u[1]; while(setsearch(u,a[n]++),)); u=setunion(u,[a[n]]); while( #u>1 && u[2]==u[1]+1, u=u[2..#u]); a[n]+a[n-1]>#a || a[a[n]+a[n-1]]=-1)}

%Y Cf. A255003, A256210.

%Y For indices of primes see A256212.

%K nonn

%O 1,2

%A _Eric Angelini_ and _M. F. Hasler_, Feb 11 2015

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 April 25 09:38 EDT 2024. Contains 371967 sequences. (Running on oeis4.)