big = 1 000 000 s = 0 S = [] unseen = 1 seen(v) = if (v < big, bittest(s, v), setsearch(S, v)) see(v) = if (v < big, s = bitor(s, 2^v), S = setunion(S, [v])); while (seen(unseen), unseen++) a = [0] n = 0 b = vector(10 000) u = 1 emit(v) = { n++; see(v); if (v <= #b, b[v] = n; while (b[u], print (u " " b[u]); if (u++ > #b, quit; ); ); ); if (n > #a, a = concat(a, vector(#a)); ); a[n] = v; } other(p) = { for (v = unseen, oo, if (!seen(v) && (p==1 || gcd(p, v)!=1), return (v); ); ); } { emit(1); for (k = 1, oo, emit(other(a[k])); emit(other(a[k])); ); } quit