%I #14 Jul 19 2017 20:28:54
%S 1,4,6,8,10,12,9,15,18,14,16,20,22,24,21,27,30,25,35,28,26,32,34,36,
%T 33,39,42,38,40,44,46,48,45,50,52,54,51,57,60,55,65,70,49,56,58,62,64,
%U 66,63,69,72,68,74,76,78,75,80,82,84,77,88,86,90,81,87,93
%N Nonprime EKG sequence, cf. A064413: a(1) = 1, a(2) = 4 and for n > 2, a(n) = smallest composite number not already used which shares a factor with a(n-1).
%C A239965 gives the position of the n-th nonprime; a(A239965(n))=A018252(n).
%H Reinhard Zumkeller, <a href="/A240024/b240024.txt">Table of n, a(n) for n = 1..10000</a>
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/EKGSequence.html">EKG Sequence</a>
%H <a href="/index/Ed#EKG">Index entries for sequences related to EKG sequence</a>
%t a = {1, 4}; Do[k = 6; While[Or[PrimeQ@ k, MemberQ[a, k], CoprimeQ[a[[i - 1]], k]], k++]; AppendTo[a, k], {i, 3, 66}]; a (* _Michael De Vlieger_, Sep 01 2016 *)
%o (Haskell)
%o import Data.List (delete, genericIndex)
%o a240024 n = genericIndex a240024_list (n - 1)
%o a240024_list = 1 : ekg 4 a002808_list where
%o ekg x zs = f zs where
%o f (y:ys) = if gcd x y > 1 then y : ekg y (delete y zs) else f ys
%Y Cf. A064413, A064664 (EKG sequence).
%Y Cf. A018252, A075570, A239965.
%K nonn
%O 1,2
%A _Reinhard Zumkeller_, Apr 30 2014