OFFSET
1,2
COMMENTS
Permutation of natural numbers.
LINKS
Andrew Howroyd, Table of n, a(n) for n = 1..10000 (terms 1..133 from Paolo P. Lava)
EXAMPLE
a(1)=1 -> next term is 2, prime.
a(2)=2 -> the sum of the next two terms 3 + 4 = 7, prime.
a(3)=3 -> 4 + 5 + 8 = 17, prime.
a(4)=4 -> 5 + 8 + 6 + 10 = 29, prime.
a(5)=5 -> 8 + 6 + 10 + 7 + 12 = 43, prime.
a(6)=8 but we also have a(7)=6 that must be covered before a(6).
Therefore the sequence became: 1, 2, 3, 4, 5, 8, 6, 10, 7, 12, 9, 11, 18, ... with 10 + 7 + 12 + 9 + 11 + 18 = 67, prime.
Then coming back to a(6)=8: 1, 2, 3, 4, 5, 8, 6, 10, 7, 12, 9, 11, 18, 16, ... with 6 + 10 + 7 + 12 + 9 + 11 + 18 + 16 = 89.
It could happen that two or more sums must be satisfied at the same step. If it is not possible we must change the most recent entries. For example, the sequence up to a(30) is: 1, 2, 3, 4, 5, 8, 6, 10, 7, 12, 9, 11, 18, 16, 13, 22, 14, 15, 17, 23, 19, 20, 34, 21, 24, 25, 26, 33, 27, 40.
Now a(13)=18 and a(17)=14 must be satisfied in a(31) but 16 + 13 + 22 + 14 + 15 + 17 + 23 + 19 + 20 + 34 + 21 + 24 + 25 + 26 + 33 + 27 + 40 = 389 (odd) and 15 + 17 + 23 + 19 + 20 + 34 + 21 + 24 + 25 + 26 + 33 + 27 + 40 = 324 (even) and no integer a(31) can satisfy the system 389 + a(31) = p1 and 324 + a(31) = p2, with p1 and p2 both prime. Therefore we must change a(17)=14 into a new minimum value, in this case a(17)=15, and restart the sequence from that point.
PROG
(PARI)
PTest(t, u)={for(i=1, #u, if(!isprime(t-u[i]), return(0))); 1}
XTest(u)={forprime(p=2, #u, if(#Set(u%p) >= p, return(0))); 1}
seq(n)={
my(v=vector(n), f=vector(2*n), M=Map(), p=1, t=0);
for(k=1, #v, my(S, X);
while(f[p], p++);
if(mapisdefined(M, k, &S), mapdelete(M, k), S=[]);
for(q=p, oo, if(!f[q] && PTest(t+q, S),
X = if(mapisdefined(M, q+k, &X), concat(X, [t+q]), [t+q]);
if(XTest(X), mapput(M, q+k, X); t += q; f[q]=1; v[k]=q; break);
)));
v
} \\ Andrew Howroyd, Jun 05 2021
CROSSREFS
KEYWORD
nonn
AUTHOR
Paolo P. Lava, Nov 19 2012
STATUS
approved