login
A377947
Unfriendly EKG sequence: a(1) = 1; a(2) = 3; for n > 2, a(n) = least number not already used which shares a factor with a(n-1) and is less than half or more than twice a(n-1).
0
1, 3, 9, 21, 6, 2, 8, 18, 4, 10, 22, 46, 12, 26, 54, 14, 30, 5, 15, 33, 11, 44, 16, 34, 70, 7, 28, 58, 20, 42, 86, 24, 50, 102, 17, 51, 105, 25, 55, 115, 23, 69, 27, 57, 19, 76, 32, 66, 134, 36, 74, 150, 35, 75, 153, 39, 13, 52, 106, 38, 78, 158, 40, 82, 166, 48, 98, 198, 45, 93, 31, 124
OFFSET
1,2
FORMULA
a(n) = least number not already used such that gcd(a(n), a(n-1)) > 1 and ((a(n) < a(n-1) / 2) or (a(n) > a(n-1) * 2)).
EXAMPLE
a(3) = 9 since it is the least unused number that shares a factor with a(2) = 3 and is less than 3/2 or greater than 3*2.
PROG
(Python)
from math import gcd
from itertools import count, islice
def c(k, an): return gcd(k, an) > 1 and not an <= 2*k <= 4*an
def agen(): # generator of terms
yield 1
aset, an, m = {1}, 3, 2
while True:
yield an
aset.add(an)
an = next(k for k in count(m) if k not in aset and c(k, an))
while m in aset: m += 1
print(list(islice(agen(), 72))) # Michael S. Branicky, Nov 21 2024
CROSSREFS
Cf. A064413.
Sequence in context: A146219 A197403 A305618 * A006077 A291898 A330987
KEYWORD
nonn
AUTHOR
Will Nicholes, Nov 11 2024
STATUS
approved