close
login
A387621
a(n) = n for n <= 3, a(n) = k such that k is not coprime to a(n-2) but k is coprime to a(n-1), with a(m) != k for m < n, looking first for the largest qualifying k < a(n-2), but if no such k exists, looking at the smallest k > a(n-2).
2
1, 2, 3, 4, 9, 8, 15, 14, 5, 12, 25, 6, 35, 16, 21, 10, 7, 18, 49, 20, 63, 22, 57, 11, 54, 55, 52, 45, 46, 39, 44, 27, 40, 33, 38, 51, 32, 17, 30, 119, 26, 105, 13, 102, 65, 99, 50, 93, 34, 87, 28, 81, 56, 75, 58, 69, 29, 66, 145, 64, 135, 62, 129, 31, 126, 155
OFFSET
1,2
COMMENTS
A version of the Yellowstone sequence A098550 akin to A386482, the latter a sequence that is a variant of the EKG sequence A064413.
This sequence is motivated by the fact that we find k in the cototient of a(n-2), hence we seek k < a(n-2) and if no such k is available, we seek k > a(n-2).
Sequence A387731 is also a version of the Yellowstone sequence A098550 akin to A386482 with k first smaller than a(n-1) instead of a(n-2).
First differs from A387731 for n >= 10; a(4576) = A387731(4576) = 5654.
LINKS
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^14, showing primes in red, proper prime powers in gold, squarefree composites in green, and numbers neither squarefree nor prime powers in blue and purple, where purple indicates powerful numbers that are not prime powers.
Michael De Vlieger, Efficient extensible Mathematica algorithm (efficient for input that is a product of multiple large primes).
EXAMPLE
Table of first 16 terms:
n a(n) p-adic valuation:
2 3 5 7
--------------------------------------------
1 1 .
2 2 1
3 3 . 1
4 4 2
5 9 . 2
6 8 3
7 15 . 1 1
8 14 1 . . 1
9 5 . . 1
10 12 2 1
11 25 . . 2
12 6 1 1
13 35 . . 1 1
14 16 4
15 21 . 1 . 1
16 10 1 . 1
a(4) = 4 because 4 is the smallest candidate k not coprime to a(2) = 2 but is coprime to a(3) = 3. There are no candidates k < 2 that satisfy.
a(5) = 9 because 9 is the smallest k such that gcd(k,3)>1 and gcd(k,4)=1; there are no candidates k < 3 that satisfy.
a(6) = 8 because 9 is the least k such that gcd(k,4)>1 and gcd(k,9)=1; there are no candidates k < 4 that satisfy.
a(7) = 15 because 15 is the least k such that gcd(k,9)>1 and gcd(k,8)=1; 6 and 12 are not in the sequence, but also not coprime to 8.
a(8) = 14 because 14 is the least k such that gcd(k,8)>1 and gcd(k,15)=1; 6, 10, and 12 are available but are also not coprime to 15.
a(9) = 5 because 5 is the least k such that gcd(k,15)>1 and gcd(k,14)=1; 6 and 12 are available but even like 14.
a(10) = 12 because 12 = a(8) - lpf(a(8)) = 14-2 is the least k such that gcd(k,14)>1 and gcd(k,5)=1. It is the very first candidate considered and happened to be available, etc.
MATHEMATICA
Block[{nn, c, i, j, k},
nn = 120; c[_] := False; Set[{i, j}, {2, 3}]; c[1] = c[2] = c[3] = True;
Range[3]~Join~
Reap[
Do[k = i - 1;
While[And[k > 1, Or[c[k], CoprimeQ[i, k], ! CoprimeQ[j, k] ] ], k--];
If[k == 1, k = i + 1;
While[Or[c[k], CoprimeQ[i, k], ! CoprimeQ[j, k] ], k++] ];
Set[{c[k], i, j}, {True, j, Sow[k]}], {n, 4, nn}] ][[-1, 1]] ]
PROG
(Python)
from math import gcd
from itertools import count, islice
def A387621_gen(): # generator of terms
k, m, mset, c = 2, 3, {1, 2, 3}, 4
yield from (1, 2, 3)
while True:
for i in range(k-1, c-1, -1):
if i not in mset and gcd(i, m)==1 and gcd(i, k)>1:
yield i
break
else:
for i in count(max(c, k+1)):
if i not in mset and gcd(i, m)==1 and gcd(i, k)>1:
yield i
break
k, m = m, i
mset.add(i)
while c in mset:
mset.remove(c)
c += 1
A387621_list = list(islice(A387621_gen(), 30)) # Chai Wah Wu, Sep 10 2025
CROSSREFS
Cf. A051953, A098550, A386482, A387731 (starting with k < a(n-1) instead of a(n-2)).
Sequence in context: A255509 A257862 A350359 * A340807 A329449 A365117
KEYWORD
nonn
AUTHOR
Michael De Vlieger, Sep 03 2025
STATUS
approved