big = 1 000 000 s = 0 S = [] unseen = 0 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++) { see(0); p = 2; q = 3; for (n = 1, 10 000, if (n==1, v = 1, Mod(unseen, p) == Mod(v, p), v = unseen, forstep (w = (v%p) + (unseen\p)*p, oo, p, if (Mod(w, q) == Mod(unseen, q), v = w; break; ); ); ); see(v); print (n " " v); if (n>1, p = q; q = nextprime(q+1); ); ); } quit