%I #30 Aug 28 2015 17:24:29
%S 1,2,3,5,4,7,6,11,8,9,10,13,12,17,14,15,16,19,18,23,20,21,22,25,24,29,
%T 26,27,28,31,30,37,32,33,34,35,36,41,38,39,40,43,42,47,44,45,46,49,48,
%U 53,50,51,52,55,54,59,56,57,58,61,60,67,62,63,64,65,66,71,68,69,70,73
%N a(1)=1, a(2)=2. a(n) = the smallest positive integer that does not occur earlier in the sequence and is coprime to the second-largest term occurring earlier in the sequence.
%C Sequence is a permutation of the positive integers.
%C From _Bob Selcoe_, Aug 12 2015: (Start)
%C Let z be the largest term already occurring in the sequence. Except for a(2), z is odd.
%C When n=z, the sequence is a permutation of the positive integers up to and including z.
%C 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.
%C 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)
%H Robert Israel, <a href="/A123882/b123882.txt">Table of n, a(n) for n = 1..10000</a>
%F From _Bob Selcoe_, Aug 12 2015: (Start)
%F For n>=5, where z and p are defined in "Comments":
%F a(n) = n-1, except for a(z+1) = z-1+p.
%F 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)
%e 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.
%e 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
%p N:= 1000: # to get all terms before the first term > N
%p Next:= Vector(N, i->i+1): Next[N]:= 0:
%p Prev:= Vector(N, i->i-1):
%p First:= 3: Prev[3]:= 0:
%p A[1]:= 1: A[2]:= 2:
%p Largest:= 2: Second:= 1:
%p for n from 3 do
%p p:= First;
%p while igcd(p,Second) > 1 and p <> 0 do
%p p:= Next[p];
%p od:
%p if p = 0 then break fi;
%p A[n]:= p;
%p if Next[p] <> 0 then Prev[Next[p]]:= Prev[p] fi;
%p if p = First then First:= Next[p] else Next[Prev[p]]:= Next[p] fi;
%p if p > Largest then
%p Second:= Largest; Largest:= p
%p elif p > Second then
%p Second:= p
%p fi
%p od:
%p seq(A[k],k=1..n-1); # _Robert Israel_, Aug 21 2015
%t 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 *)
%Y Cf. A123883.
%K nonn
%O 1,2
%A _Leroy Quet_, Oct 16 2006
%E Extended by _Ray Chandler_, Oct 16 2006
|