s = 0 unseen = 1 seen(v) = bit test(s, v) see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++) other(m) = { my (s=Set(1), b=binary(m)); for (i=2, #b, s = setunion(s, Set(apply(v -> 2*v+b[i], s))); ); for (i=1, oo, if (!seen(s[i]), see(s[i]); return (s[i]); ); ); } for (n=1, 10 000, print (n " " other(prime(n)))) quit