OFFSET
1,2
COMMENTS
See A253074 for an essentially identical sequence (with a proof that the sequence is a permutation).
Sequence A253074 is defined in the same way, but starting with 0. This happens to produce the same sequence from the next term on. This is the case (M,N) = (2,0) in the family of sequences where M consecutive terms yield N primes in their pairwise sums, see the wiki page for other examples. - M. F. Hasler, Nov 26 2019
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
M. F. Hasler, Prime sums from neighboring terms, OEIS wiki, Nov. 23, 2019
FORMULA
EXAMPLE
a(3) = 5 because 1 and 3 have already been used and both 3 + 2 = 5 and 3 + 4 = 7 are prime while 3 + 5 = 8 is not prime.
MAPLE
N:= 1000; # to get a[n] for n up to N
A:= {1};
a[1]:= 1;
for n from 2 to N do
mA:= max(A);
R:= {$1..mA} minus A;
for x in R do
if not isprime(a[n-1]+x) then
a[n]:= x;
break
fi
od:
if not assigned(a[n]) then
for x from mA+1 do
if not isprime(a[n-1]+x) then
a[n]:= x;
break
fi
od
fi;
A:= A union {x};
od:
seq(a[n], n=1..N); # Robert Israel, Jun 03 2014
MATHEMATICA
f[ s_ ]:=Block[ {k=1, a=s[ [ -1 ] ]}, While[ Or[ MemberQ[ s, k ], PrimeQ[ a+k ] ], k++ ]; Append[ s, k ] ]; Nest[ f, {1}, 121 ] (* Zak Seidov, Oct 21 2009 *)
a={1}; z=Range[2, 2002]; z=Complement[z, a]; While[Length[z]>1, If[!PrimeQ[z[[1]]+Last[a]], AppendTo[a, z[[1]]], If[!PrimeQ[z[[2]]+Last[a]], AppendTo[a, z[[2]]], AppendTo[a, z[[3]]]]]; z=Complement[z, a]]; Print[a] (* significantly faster *) (* Vladimir Joseph Stephan Orlovsky, May 03 2011 *)
PROG
(Haskell)
import Data.List (delete)
a055266 n = a055266_list !! (n-1)
a055266_list = 1 : f 1 [2..] where
f u vs = g vs where
g (w:ws) | a010051' (u + w) == 0 = w : f w (delete w vs)
| otherwise = g ws
-- Reinhard Zumkeller, Jan 14 2015
(PARI) v=[1]; n=1; while(n<100, if(!isprime(n+v[#v])&&!vecsearch(vecsort(v), n), v=concat(v, n); n=0); n++); v \\ Derek Orr, Jun 08 2015
(PARI) A055266_upto(n=99, u=1, U, a)={vector(n, n, n=u; while(bittest(U, n-u)|| isprime(a+n), n++); if(n>u, U+=1<<(n-u), U>>=-u+u+=valuation(U+2, 2)); a=n) + if(default(debug), print([u]))} \\ Optional args allow to tweak computation. If debug > 0, print least unused number at the end. - M. F. Hasler, Nov 25 2019
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Henry Bottomley, May 09 2000
EXTENSIONS
Corrected by Zak Seidov, Oct 21 2009
Name edited by M. F. Hasler, Nov 26 2019
STATUS
approved