%I #7 Jan 24 2025 11:58:50
%S 1,1,2,3,4,2,5,6,3,4,6,7,8,9,10,5,11,12,8,10,13,14,7,15,9,12,14,16,17,
%T 18,19,20,15,21,18,16,20,22,11,23,24,22,25,26,13,27,28,21,24,26,28,29,
%U 30,27,31,32,33,34,17,35,25,30,34,36,32,37,38,19,39,40
%N Lexicographically earliest sequence of positive integers such that any value in the sequence, say v, appears at most twice, and in case v appears twice, then v divides the product of the values surrounded by the two occurrences of v.
%C Every positive integer appears twice in the present sequence (we can use the same arguments as in A380298).
%H Rémy Sigrist, <a href="/A380300/b380300.txt">Table of n, a(n) for n = 1..10000</a>
%H Rémy Sigrist, <a href="/A380300/a380300.gp.txt">PARI program</a>
%o (PARI) \\ See Links section.
%o (Python)
%o from math import prod
%o from itertools import count, islice
%o def agen(): # generator of terms
%o alst, adict, an, m = [], dict(), 1, 1
%o for n in count(1):
%o yield an
%o alst.append(an)
%o adict[an] = [n] if an not in adict else adict[an] + [n]
%o an = next(k for k in count(m) if k not in adict or (len(adict[k])==1 and prod(alst[adict[k][0]:n])%k==0))
%o while m in adict and len(adict[m]) > 1: m += 1
%o print(list(islice(agen(), 70))) # _Michael S. Branicky_, Jan 19 2025
%Y See A380298 for a similar sequence.
%K nonn,new
%O 1,3
%A _Rémy Sigrist_, Jan 19 2025