A103683 a(1)=1, a(2)=2, a(3)=3, a(n) = smallest positive integer not occurring earlier in sequence and coprime to a(n-1), a(n-2) and a(n-3).
1, 2, 3, 5, 7, 4, 9, 11, 13, 8, 15, 17, 19, 14, 23, 25, 27, 16, 29, 31, 21, 10, 37, 41, 33, 20, 43, 47, 39, 22, 35, 53, 51, 26, 49, 55, 57, 32, 59, 61, 45, 28, 67, 71, 65, 6, 73, 77, 79, 12, 83, 85, 89, 18, 91, 95, 97, 24, 101, 103, 107, 30, 109, 113, 119, 36, 115, 121, 127, 34
Offset: 1
Keywords
Links
- Alois P. Heinz, Table of n, a(n) for n = 1..10000
Programs
-
Maple
ina:= proc(n) false end: a:= proc(n) option remember; local k; if n<4 then k:= n else for k from 4 while ina(k) or igcd(k, a(n-1))<>1 or igcd(k, a(n-2))<>1 or igcd(k, a(n-3))<>1 do od fi; ina(k):= true; k end: seq(a(n), n=1..120); # Alois P. Heinz, Jan 19 2011
-
Mathematica
f[s_] := Block[{k = 1, l = Take[s, -3]}, While[ Union[ GCD[k, l]] != {1} || MemberQ[s, k], k++]; Append[s, k]]; Nest[f, {1, 2, 3}, 70] (* Robert G. Wilson v, Jun 26 2011 *)
-
Python
from math import gcd from itertools import islice def agen(): # generator of terms aset, b, c, d = {1, 2, 3, 5}, 2, 3, 5 yield from [1, b, c, d] while True: k = 1 while k in aset or any(gcd(t, k) != 1 for t in [b, c, d]): k+= 1 b, c, d = c, d, k aset.add(k) yield k print(list(islice(agen(), 70))) # Michael S. Branicky, Apr 18 2022
Extensions
More terms from Robert G. Wilson v, Mar 30 2005
Comments