Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #17 Jan 13 2025 08:54:03
%S 4,6,8,10,9,14,12,15,16,22,18,26,20,21,24,34,27,38,25,28,30,46,32,35,
%T 36,33,40,58,39,62,42,44,48,45,50,74,52,51,54,82,49,86,55,57,56,94,60,
%U 63,64,66,65,106,68,70,72,69,76,118,75,122,78,77,80,85,81,134,84,87,88,142
%N a(n) = the smallest integer > n that has yet to occur in the sequence, and that is not coprime to n.
%C Is this a permutation of the composite integers?
%H Robert Israel, <a href="/A162600/b162600.txt">Table of n, a(n) for n = 2..10000</a>
%p Cands:= remove(isprime,[$5..1000]): nC:= nops(Cands):
%p R:= 4: r:= 4: found:= true:
%p for n from 3 while found do
%p found:= false;
%p for i from 1 to nC+3-n do
%p if Cands[i] > n and igcd(n,Cands[i]) > 1 then
%p r:= Cands[i];
%p R:= R,r;
%p Cands:= subsop(i=NULL, Cands);
%p found:= true;
%p break
%p fi;
%p od;
%p od:
%p R; # _Robert Israel_, Jan 12 2025
%t g[n_] := g[n] = Block[{k = n + 1, t = Table[ g@i, {i, 2, n - 1}]}, While[ MemberQ[t, k] || GCD[n, k] == 1, k++ ]; k]; Table[ g@n, {n, 2, 71}] (* or *) f[lst_] := Block[{len = 2 + Length@lst}, k = 1 + len; While[ MemberQ[lst, k] || GCD[len, k] == 1, k++ ]; Append[lst, k]]; Nest[f, {}, 70] (* _Robert G. Wilson v_, Aug 17 2009 *)
%o (Python)
%o from math import gcd
%o from sympy import isprime
%o from itertools import count, islice
%o def agen(): # generator of terms
%o aset, m = set(), 4
%o for n in count(2):
%o an = next(k for k in count(max(n+1, m)) if k not in aset and gcd(n, k) > 1)
%o aset.add(an)
%o while m in aset or isprime(m): m += 1
%o yield an
%o print(list(islice(agen(), 70))) # _Michael S. Branicky_, Jan 13 2025
%K nonn
%O 2,1
%A _Leroy Quet_, Jul 07 2009
%E a(17) and further terms from _Robert G. Wilson v_, Aug 17 2009