cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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

This page as a plain text file.
%I A255004 #18 Mar 22 2019 05:25:43
%S A255004 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 A255004 41,24,43,25,47,26,53,27,28,30,32,33,59,34,61,35,67,36,38,39,71,40,73,
%U A255004 42,44,79,45,46,83,48,89,97,49,50,51,101,103,52,107,54
%N A255004 Lexicographically earliest permutation of positive integers such that a(a(n)+a(n+1)) is prime for all n.
%C A255004 This is the sequence V defined in the Comments on A255003.
%H A255004 Alois P. Heinz, <a href="/A255004/b255004.txt">Table of n, a(n) for n = 1..10000</a>
%p A255004 N:= 100: # to get a(n) for n <= N
%p A255004 maxprime:= 2:
%p A255004 maxa:= 2:
%p A255004 a[1]:= 1:
%p A255004 a[2]:= 2:
%p A255004 needprime:= {3}:
%p A255004 for n from 3 to N do
%p A255004   if member(n,needprime) then
%p A255004      a[n]:= nextprime(maxprime);
%p A255004      maxprime:= a[n];
%p A255004   else
%p A255004      if isprime(maxa+1) and maxa+1<= maxprime then a[n]:= maxa+2
%p A255004      else a[n]:= maxa+1
%p A255004      fi;
%p A255004      maxa:= a[n];
%p A255004   fi;
%p A255004   needprime:= needprime union {a[n-1]+a[n]};
%p A255004 od:
%p A255004 seq(a[n],n=1..N); # _Robert Israel_, Mar 26 2015
%t A255004 M = 100;
%t A255004 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 A255004 Array[a, M] (* _Jean-François Alcover_, Mar 22 2019, after _Robert Israel_ *)
%o A255004 (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 A255004 Cf. A255003, A256210.
%Y A255004 For indices of primes see A256212.
%K A255004 nonn
%O A255004 1,2
%A A255004 _Eric Angelini_ and _M. F. Hasler_, Feb 11 2015