\\ 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, 10 000, 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); ); ); ); ); ); print (v " " n); mapput(val, n, v); idx = setunion(idx, [n]); while (setsearch(idx, nxt), nxt++; ); ); } quit