OFFSET
1,2
COMMENTS
Sequence is a permutation of the positive integers.
From Bob Selcoe, Aug 12 2015: (Start)
Let z be the largest term already occurring in the sequence. Except for a(2), z is odd.
When n=z, the sequence is a permutation of the positive integers up to and including z.
Let p be the smallest prime number that is not a factor of z-1. When n>=3, z+1 is coprime to both z and z-1+p.
When n>=5, a(n) is the smallest positive integer not yet having occurred in the sequence that is coprime to a(n-1). (End)
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
FORMULA
From Bob Selcoe, Aug 12 2015: (Start)
For n>=5, where z and p are defined in "Comments":
a(n) = n-1, except for a(z+1) = z-1+p.
a(n) = a(n-1)+1, except for a(z+1) = a(z)+p and a(z+2) = a(z)+2 (here, p can also be defined as the smallest prime that is not a factor of a(z)). (End)
EXAMPLE
The second-largest integer among the first 8 terms of the sequence is 7. Those positive terms not occurring among the first 8 terms form the sequence 8,9,10,12,13,...; of these, 8 is the smallest that is coprime to 7. So a(9)=8.
z=43: a(44)=47 because the smallest prime not a factor of z-1 = 42 is 5, and 42+5 = 47. - Bob Selcoe, Aug 12 2015
MAPLE
N:= 1000: # to get all terms before the first term > N
Next:= Vector(N, i->i+1): Next[N]:= 0:
Prev:= Vector(N, i->i-1):
First:= 3: Prev[3]:= 0:
A[1]:= 1: A[2]:= 2:
Largest:= 2: Second:= 1:
for n from 3 do
p:= First;
while igcd(p, Second) > 1 and p <> 0 do
p:= Next[p];
od:
if p = 0 then break fi;
A[n]:= p;
if Next[p] <> 0 then Prev[Next[p]]:= Prev[p] fi;
if p = First then First:= Next[p] else Next[Prev[p]]:= Next[p] fi;
if p > Largest then
Second:= Largest; Largest:= p
elif p > Second then
Second:= p
fi
od:
seq(A[k], k=1..n-1); # Robert Israel, Aug 21 2015
MATHEMATICA
f[l_List] := Block[{s = Sort[l][[ -2]], k = 1}, While[GCD[k, s] > 1 || MemberQ[l, k], k++ ]; Append[l, k]]; Nest[f, {1, 2}, 75] (* Ray Chandler, Oct 16 2006 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Leroy Quet, Oct 16 2006
EXTENSIONS
Extended by Ray Chandler, Oct 16 2006
STATUS
approved