big = 1 000 000 s = 0 S = Set([]) unseen = 1 seen(v) = if (v < big, bit test(s, v), set search(S, v)) see(v) = if (v < big, s = bit or(s, 2^v), S = set union(S, Set([v]))); while (seen(unseen), unseen++) ok(n) = { my (m=0); forprime (p=2, oo, if (n==0, return (1), my (d=n%p); if (bittest(m, d), return (0), m+=2^d; ); n\=p; ); ); } other(p) = { see(p); for (v=unseen, oo, if (!seen(v) && ok(p+v), return (v); ); ); } for (n=1, 10 000, print (n " " v=if (n==1, 1, other(v)))) quit