login
a(n) = n for n <= 3; for n >= 4, a(n) is the smallest positive integer that has not appeared previously in this sequence and shares a factor with a(n-1) + a(n-2) + a(n-3).
1

%I #41 Dec 30 2023 23:07:49

%S 1,2,3,4,6,13,23,7,43,73,9,5,12,8,10,14,16,15,18,21,20,59,22,101,24,

%T 27,19,25,71,30,26,127,33,28,32,31,35,34,36,39,109,38,40,11,89,42,44,

%U 45,131,46,37,48,262,347,51,50,49,52,151,54,257,55,56,58,65

%N a(n) = n for n <= 3; for n >= 4, a(n) is the smallest positive integer that has not appeared previously in this sequence and shares a factor with a(n-1) + a(n-2) + a(n-3).

%C Conjecture: This sequence is a permutation of the natural numbers.

%H Yifan Xie, <a href="/A363198/b363198.txt">Table of n, a(n) for n = 1..2000</a>

%t a[1] = 1; a[2] = 2; a[3] = 3; a[n_] := a[n] = Module[{s, i = 1}, s = a[n - 1] + a[n - 2] + a[n - 3]; While[MemberQ[a /@ Range[1, n - 1], i] || GCD[s, i] == 1, i++]; i];

%t Table[a[n], {n, 1, 65}] (* _Robert P. P. McKone_, Dec 30 2023 *)

%o (PARI) lista(nn) = {my(v = [1, 2, 3]); for(n=4, nn, my(t=1); while(prod(X=1, n-1, v[X]-t)==0 || gcd(v[n-3]+v[n-2]+v[n-1], t)==1, t++); v=concat(v, t)); v;}

%o (Python)

%o from math import gcd

%o a = [1, 2, 3]

%o t = set(a)

%o def next_element():

%o s = a[-1] + a[-2] + a[-3]

%o n = 1

%o while n in t or gcd(s, n) == 1:

%o n += 1

%o return n

%o def a_seq(ul):

%o for _ in range(4, ul + 1):

%o nn = next_element()

%o a.append(nn)

%o t.add(nn)

%o return a

%o print(a_seq(65)) # _Robert P. P. McKone_, Dec 30 2023

%Y Cf. A064413, A337136.

%K nonn,easy

%O 1,2

%A _Yifan Xie_, May 21 2023