OFFSET
1,1
COMMENTS
See A371618 for the indices where the primes first appear.
LINKS
Scott R. Shannon, Table of n, a(n) for n = 1..10000
Scott R. Shannon, Image of the first 250000 terms. Prime terms are shown in red.
EXAMPLE
a(7) = 10 as a(6) = 4 and, although 2 and 6 share factors with 4, 2 and 4 form a previous adjacent pair, as do 4 and 6. This leaves 10 as the smallest number that shares a factor with 4 while 4 and 10 have not previously appeared as adjacent terms.
MATHEMATICA
nn = 120; c[_] := {}; a[1] = j = 2; c[2] = {2};
Do[If[PrimePowerQ[j],
(k = 1;
While[Or[j == # k, CoprimeQ[j, # k], ! FreeQ[c[j], # k]], k++];
k *= #) &[FactorInteger[j][[1, 1]]],
k = FactorInteger[j][[1, 1]];
While[Or[j == k, CoprimeQ[j, k], ! FreeQ[c[j], k]], k++] ];
Set[{a[n], c[j], c[k], j},
{k, Union[c[j], {k}], Union[c[k], {j}], k}], {n, 2, nn}];
Array[a, nn] (* Michael De Vlieger, Jun 22 2024 *)
PROG
(Python)
from math import gcd
from itertools import count, islice
def agen(): # generator of terms
an, adjacent = 2, {2: set()}
while True:
yield an
A = adjacent[an]
m = next(k for k in count(2) if k!=an and gcd(k, an)>1 and k not in A)
adjacent[an].add(m)
if m not in adjacent: adjacent[m] = set()
adjacent[m].add(an)
an = m
print(list(islice(agen(), 84))) # Michael S. Branicky, Jun 22 2024
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Scott R. Shannon, Jun 22 2024
STATUS
approved