login
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

%I #12 Nov 30 2024 13:01:29

%S 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,

%T 28,58,20,42,86,24,50,102,17,51,105,25,55,115,23,69,27,57,19,76,32,66,

%U 134,36,74,150,35,75,153,39,13,52,106,38,78,158,40,82,166,48,98,198,45,93,31,124

%N 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).

%F 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)).

%e 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.

%o (Python)

%o from math import gcd

%o from itertools import count, islice

%o def c(k, an): return gcd(k, an) > 1 and not an <= 2*k <= 4*an

%o def agen(): # generator of terms

%o yield 1

%o aset, an, m = {1}, 3, 2

%o while True:

%o yield an

%o aset.add(an)

%o an = next(k for k in count(m) if k not in aset and c(k, an))

%o while m in aset: m += 1

%o print(list(islice(agen(), 72))) # _Michael S. Branicky_, Nov 21 2024

%Y Cf. A064413.

%K nonn

%O 1,2

%A _Will Nicholes_, Nov 11 2024