OFFSET
2,1
COMMENTS
It has been proved that a(n) is its own inverse, i.e., that a(a(n)) = n for all n > 1.
LINKS
Robert Israel, Table of n, a(n) for n = 2..10000
Robert Israel, Proof that a(n) is its own inverse, Mathematics Stack Exchange
EXAMPLE
a(2), must be at least 4 to differ by 2, but 4 and 2 share a factor of 2 so a(2) must be 5.
a(3), must be at least 5 but 5 is taken by a(2), so it is at least 6, but 6 shares a factor with 3 so it must be at least 7, 7 satisfies all three requirements thus a(3)=7.
MAPLE
S:= [$2..1000]:
while S <> {} do
n:= S[1];
k:= ListTools:-SelectFirst(t -> S[t] > n+1 and igcd(n, S[t])=1, [$2..nops(S)]);
if k = NULL then break fi;
R[n]:= S[k]; R[S[k]]:= n;
S:= subsop(1=NULL, k=NULL, S);
od:
seq(R[i], i=2..n-1); # Robert Israel, Jul 25 2017
MATHEMATICA
a = {1, 5}; Do[k = 2; While[Nand[CoprimeQ[n, k], ! MemberQ[a, k], Abs[n - k] >= 2], k++]; AppendTo[a, k], {n, 3, 96}]; Rest@ a (* Michael De Vlieger, Jul 21 2017 *)
PROG
(Haskell)
f 1=[]
f n|l<-f$n-1=l++[[i|i<-[2..], gcd i n<2, all(/=i)l, abs(n-i)>1]!!0]
-- defines a function f that when given n will generate the first n terms as a list --
CROSSREFS
KEYWORD
nonn
AUTHOR
Eamon Olive, Jul 21 2017
STATUS
approved