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++)

\\ first unseen number v such that p AND v = 0
cc = [0]
avoid(p) = {
	my (w=1, b, c);
	for (e=0, oo,
		if (!bittest(p, e),
			if (#cc==w,
				cc=concat(cc, vector(#cc));
			);
			b = 2^e;
			for (k=1, w,
				c = cc[w+k] = b+cc[k];
				if (!seen(c),
					return (c);
				);
			);

			w*=2;
		);
	);
}

{
	see(0);
	print ("0 0");
	x = vector(5000);
	for (n=1, #x,
		see(v=avoid(x[n]));
		print (n " " v);
		for (m=n+1, min(#x, 2*n),
			x[m] = bitor(x[m], v);
		);
	);
}

quit