login
A386482
a(1)=1, a(2)=2; thereafter a(n) is either the greatest number k < a(n-1) not already used such that gcd(k, a(n-1)) > 1, or if no such k exists then a(n) is the smallest number k > a(n-1) not already used such that gcd(k, a(n-1)) > 1.
46
1, 2, 4, 6, 3, 9, 12, 10, 8, 14, 7, 21, 18, 16, 20, 15, 5, 25, 30, 28, 26, 24, 22, 11, 33, 27, 36, 34, 32, 38, 19, 57, 54, 52, 50, 48, 46, 44, 42, 40, 35, 45, 39, 13, 65, 60, 58, 56, 49, 63, 51, 17, 68, 66, 64, 62, 31, 93, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 55, 75, 69, 23, 92, 94, 47, 141, 138, 136, 134, 132, 130, 128
OFFSET
1,2
COMMENTS
Similar to the EKG sequence A064413, but whereas in that sequence a(n) is chosen to be as small as possible, here the primary goal is to choose a(n) to be less than a(n-1) and as close to it as possible. This sequence first differs from the EKG sequence at n = 8, where a(8) = k = 10 is closer to a(7) = 12 than A064413(8) = 8 is.
A significant difference from the EKG sequence is that the primes do not appear in their natural order. Also, it is not always true that a prime p is preceded by 2*p when it first appears. 4k+3 primes appear to be preceded by smaller multiples than 4k+1 primes.
It is conjectured that every positive number appears.
It is interesting to study what happens if the first two terms are taken to be 1,s, with s >= 2, or if the first s terms are taken to be 1,2,3,...,s, with s >= 2. Call two such sequences equivalent if they eventually merge. The 1,3 and 1,2,3 sequences merge with each other after half-a-dozen terms. But at present we do not know if they merge with the 1,2 sequence.
It appears that many sequences that start 1,s and 1,2,3,...,s with small s merge with one of the sequences 1,2 or 1,2,3 or 1,2,3,...,11.
[The preceding comments are from Geoffrey Caveney's emails.]
From Michael De Vlieger, Aug 15 2025: (Start)
There are long runs of terms with the same parity in this sequence. For example, beginning at a(481) = 948, there are 100 consecutive even terms. Starting with a(730076) = 1026330, there are 100869 consecutive even terms, followed by 36709 consecutive odd terms. Runs of even terms tend to be longer than those of odd.
There are long runs of first differences of -2 and -6 in this sequence, and that there appear to be three phases. The predominant (A) phase has a(n) = a(n-1)-2, the second (B) phase has a(n) = a(n-1)-6, and then there is a turbulent (C) phase [C] with varied differences.
Generally the even runs correspond to differences a(n)-a(n-1) = 2 and feature square-free terms separated by an odd number of terms in A126706. Phase [C] tends to be largely odd squarefree semiprimes and includes prime powers. (End)
REFERENCES
Geoffrey Caveney, Emails to N. J. A. Sloane, Aug 13 2025 - Aug 15 2025.
LINKS
Rémy Sigrist, PARI program
Michael De Vlieger, Log log scatterplot of a(n), n = 1..2^20.
Michael De Vlieger, Log log scatterplot of a(n), n = 1..2^16, showing primes in red, proper prime powers in gold, squarefree composites in green, and numbers that are neither squarefree nor prime powers in blue and purple, where purple represents powerful numbers that are not prime powers.
MAPLE
A386482 := proc(n)
local k, kused, i ;
option remember ;
if n <= 2 then
n;
else
for k from procname(n-1)-1 to 1 by -1 do
kused := false;
for i from 1 to n-1 do
if procname(i) = k then
kused := true ;
break;
end if;
end do:
if not kused and igcd(k, procname(n-1)) > 1 then
return k;
end if;
end do:
for k from procname(n-1)+1 do
kused := false;
for i from 1 to n-1 do
if procname(i) = k then
kused := true ;
break;
end if;
end do:
if not kused and igcd(k, procname(n-1)) > 1 then
return k;
end if;
end do:
end if;
end proc:
seq(A386482(n), n=1..100) ; # R. J. Mathar, Sep 07 2025
MATHEMATICA
aList[n_] := Module[{an = 2, aset = <|2 -> True|>, m}, Reap[Sow[1]; Sow[an];
Do[m = SelectFirst[Range[an - 1, 2, -1], ! KeyExistsQ[aset, #] && GCD[#, an] > 1 & ];
If[MissingQ[m], m = NestWhile[# + 1 &, an + 1, !(! KeyExistsQ[aset, #] && GCD[#, an] > 1) & ]];
aset[m] = True; an = m; Sow[an], {n - 2}]][[2, 1]]]; aList[83] (* Peter Luschny, Aug 15 2025 *)
PROG
(PARI) \\ See Links section.
(Python)
from math import gcd
from itertools import count, islice
def A386482_gen(): # generator of terms
yield 1
an, aset = 2, {2}
while True:
yield an
m = next((k for k in range(an-1, 1, -1) if k not in aset and gcd(k, an) > 1), False)
if not m: m = next(k for k in count(an+1) if k not in aset and gcd(k, an) > 1)
an = m
aset.add(an)
print(list(islice(A386482_gen(), 83))) # Michael S. Branicky, Aug 15 2025
CROSSREFS
Cf. A064413 (EKG), A387072 (inverse), A387073 (record high points), A387074 (indices of record high points), A387075 (first differences), A387076 (primes in order of appearance), A387077 (indices of primes), A387078 (run lengths of consecutive odd and even terms), A387080 (variant that begins with 1,3).
Sequence in context: A357777 A348086 A122280 * A394418 A365259 A356851
KEYWORD
nonn,look
AUTHOR
N. J. A. Sloane, Aug 15 2025, based on email messages from Geoffrey Caveney
STATUS
approved