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).
LINKS
Michael De Vlieger, Table of n, a(n) for n = 1..16384
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
CROSSREFS
KEYWORD
nonn
AUTHOR
Michael De Vlieger, Sep 03 2025
STATUS
approved
