login
Smallest number which is coprime to the last two predecessors and has not yet appeared; a(1)=1, a(2)=2.
45

%I #101 Jun 11 2022 18:06:30

%S 1,2,3,5,4,7,9,8,11,13,6,17,19,10,21,23,16,15,29,14,25,27,22,31,35,12,

%T 37,41,18,43,47,20,33,49,26,45,53,28,39,55,32,51,59,38,61,63,34,65,57,

%U 44,67,69,40,71,73,24,77,79,30,83,89,36,85,91,46,75,97,52,81

%N Smallest number which is coprime to the last two predecessors and has not yet appeared; a(1)=1, a(2)=2.

%C Equivalently, this is the lexicographically earliest sequence of positive numbers satisfying the condition that each term is relatively prime to the next two terms. - _N. J. A. Sloane_, Nov 03 2014

%C Empirically, the points lie roughly on two lines: if n == 2 mod 3 then a(n) ~= 2n/3, otherwise a(n) ~= 4n/3. See A249680-A249683 for the three trisections, and see also the Sigrist scatterplot. - _N. J. A. Sloane_, Nov 03 2014, Nov 04 2014

%C All primes and prime powers occur, and the primes occur in their natural order. For any prime p, p occurs before p^2 before p^3, ...

%C Empirically, this is a permutation of the natural numbers, with inverse A084933: a(A084933(n))=A084933(a(n))=n. It seems that there are no further fixed points after {1,2,3,8,33,39}. Empirically, a(n) mod 2 = A011655(n+1); ABS(a(n)-n) < n; a(3*n+1)>n; a(3*n+2)<n. - _Reinhard Zumkeller_, Dec 16 2007

%C For a(n) mod 3 see A249603. - _N. J. A. Sloane_, Nov 03 2014

%C A249694(n) = GCD(a(n),a(n+3)). - _Reinhard Zumkeller_, Nov 04 2014

%H Reinhard Zumkeller, <a href="/A084937/b084937.txt">Table of n, a(n) for n = 1..100000</a>

%H John P. Linderman, <a href="/A084937/a084937.txt">Table of n, a(n) for n = 1..764179</a> (about 10MB)

%H Rémy Sigrist, <a href="/A084937/a084937.png">Scatterplot of the first 2500 terms</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%p N:= 1000: # to get a(n) until the first entry > N

%p a[1]:= 1: a[2]:= 2:

%p R:= {$3..N}:

%p for n from 3 while R <> {} do

%p success:= false;

%p for r in R do

%p if igcd(r,a[n-1]) = 1 and igcd(r,a[n-2])=1 then

%p a[n]:= r;

%p R:= R minus {r};

%p success:= true;

%p break

%p fi

%p od:

%p if not success then break fi;

%p od:

%p seq(a[i], i = 1 .. n-1); # _Robert Israel_, Dec 12 2014

%t lst={1,2,3}; unused=Range[4,100]; While[n=Select[unused, CoprimeQ[#, lst[[-1]]] && CoprimeQ[#, lst[[-2]]] &, 1]; n != {}, AppendTo[lst, n[[1]]]; unused=DeleteCases[unused, n[[1]]]]; lst

%t f[s_] := Block[{k = 1, l = Take[s, -2]}, While[ Union[ GCD[k, l]] != {1} || MemberQ[s, k], k++]; Append[s, k]]; Nest[f, {1, 2}, 67] (* _Robert G. Wilson v_, Jun 26 2011 *)

%o (Haskell)

%o import Data.List (delete)

%o a084937 n = a084937_list !! (n-1)

%o a084937_list = 1 : 2 : f 2 1 [3..] where

%o f x y zs = g zs where

%o g (u:us) | gcd y u > 1 || gcd x u > 1 = g us

%o | otherwise = u : f u x (delete u zs)

%o -- _Reinhard Zumkeller_, Jan 28 2012

%o (Python)

%o from fractions import gcd

%o A084937_list, l1, l2, s, b = [1,2], 2, 1, 3, set()

%o for _ in range(10**3):

%o i = s

%o while True:

%o if not i in b and gcd(i,l1) == 1 and gcd(i,l2) == 1:

%o A084937_list.append(i)

%o l2, l1 = l1, i

%o b.add(i)

%o while s in b:

%o b.remove(s)

%o s += 1

%o break

%o i += 1 # _Chai Wah Wu_, Dec 09 2014

%o (PARI) taken(k,t=v[k])=for(i=3,k-1, if(v[i]==t, return(1))); 0

%o step(k,g)=while(gcd(k,g)>1, k++); k

%o first(n)=local(v=vector(n,i,i)); my(nxt=3,t); for(k=3,n, v[k]=step(nxt, t=v[k-1]*v[k-2]); while(taken(k), v[k]=step(v[k]+1,t)); if(v[k]==t, while(taken(k+1,t++),))); v \\ _Charles R Greathouse IV_, Aug 26 2016

%Y Cf. A084933 (inverse), A103683, A121216, A247665, A090252, A249603 (read mod 3), A249680, A249681, A249682, A249683 (trisections), A249694, A011655, A249684 (numbers that take a record number of steps to appear), A249685.

%Y Indices of primes: A249602, and of prime powers: A249575.

%Y Running counts of missing numbers: A249686, A250099, A250100; A249777, A249856, A249857.

%Y Where a(3n)>a(3n+1): A249689.

%Y See also A353706, A353709, A353710.

%K nonn,look

%O 1,2

%A _Reinhard Zumkeller_, Jun 13 2003

%E Entry revised by _N. J. A. Sloane_, Nov 04 2014