OFFSET
1,2
COMMENTS
A permutation of the positive integers. [This follows easily by standard arguments. One shows that all primes appear. If a number k is missing, find a prime term P that is much greater than k. Then the term following P will be k. Contradiction. - N. J. A. Sloane, May 06 2022]
LINKS
Michael De Vlieger, Table of n, a(n) for n = 1..10000
EXAMPLE
a(8) = 11 because, among the positive integers not occurring earlier in the sequence (6,8,10,11,12,...), 11 is the smallest which is coprime to a(7)=9, is not a(7)+1=10 and is not a(7)-1=8.
MAPLE
A:=proc(n) option remember; local t, S; S:=({$1..1000} minus {seq(A(i), i=1..n-1)}) minus {A(n-1)-1, A(n-1)+1}; t:=min(S[]); while igcd(A(n-1), t)>1 do S:=S minus {t}; t:=min(S[]) od; t end: A(1):=1: seq(A(n), n=1..200); # Alec Mihailovs (alec(AT)mihailovs.com), Aug 23 2004
MATHEMATICA
a[1] = 1; a[n_] := a[n] = Block[{t = Table[ a[i], {i, n - 1}], k = 2}, While[k == a[n - 1] - 1 || k == a[n - 1] + 1 || GCD[a[n - 1], k] != 1 || Position[t, k] != {}, k++ ]; k]; Table[ a[n], {n, 50}] (* Robert G. Wilson v, Aug 23 2004 *)
PROG
(Python)
from math import gcd
from itertools import islice
def agen(): # generator of terms
an, aset, mink = 1, {1}, 2
while True:
yield an
k = mink
while k in aset or gcd(an, k) != 1 or abs(k-an) == 1: k += 1
an = k
aset.add(an)
while mink in aset: mink += 1
print(list(islice(agen(), 72))) # Michael S. Branicky, May 02 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Leroy Quet, Aug 23 2004
EXTENSIONS
More terms from Alec Mihailovs (alec(AT)mihailovs.com) and Robert G. Wilson v, Aug 23 2004
STATUS
approved