\\ a(n) is coprime with the next n term (and the floor(n/2) previous terms) \\ each value is introduced as early as possible val = Map() \\ n -> a(n) idx = [] \\ list of known n's nxt = 1 \\ next free n mapput(val, oo, 1) idx = [oo] { for (v=1, oo, if (v==1 || isprime(v), \\ prime numbers fill the gaps n = nxt, \\ find suitable place x = 0; \\ least position with a term not coprime to v for (k=1, #idx, if (gcd(mapget(val, idx[k]), v)>1, x=idx[k], \\ all known terms between x+1 and idx[k] are coprime to v for (m=2*x+1, oo, if (2*m > idx[k], break, \\ might contain some value not coprime to v !setsearch(idx, m), n=m; break (2); ); ); ); ); ); mapput(val, n, v); idx = setunion(idx, [n]); while (setsearch(idx, nxt), print (nxt " " mapget(val, nxt)); if (nxt==10 000, break (2); ); nxt++; ); ); } quit