OFFSET
1,1
PROG
(SageMath) # from Nadia Heninger, Oct 28 2014: s is the starting point (2 in A247665, 3 here).
def gen(s):
sequence = [s]
available = range(2, 2*s)
available.pop(available.index(s))
yield s
while True:
available.extend(range(available[-1]+1, next_prime(available[-1])+1))
for i, e in enumerate(available):
if all([gcd(e, sequence[j])==1 for j in range(-len(sequence)/2, 0)]):
available.pop(i)
sequence.append(e)
yield(e)
break
g = gen(3)
[g.next() for i in range(40)] # gets first 40 terms
(Python)
from itertools import count, islice
from math import gcd
from collections import deque
def A249559_gen(): # generator of terms
aset, aqueue, c, f = {3}, deque([3]), 2, True
yield 3
while True:
for m in count(c):
if m not in aset and all(gcd(m, a) == 1 for a in aqueue):
yield m
aset.add(m)
aqueue.append(m)
if f: aqueue.popleft()
f = not f
while c in aset:
c += 1
break
CROSSREFS
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, Nov 02 2014
STATUS
approved