s = 0
unseen = 1
seen(v) = bit test(s, v)
see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++)

\\ first unseen number v such that p AND v = 0
cc = [0]
avoid(p) = {
	if (!seen(0),
		return (0);
	);

	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;
		);
	);
}

{
	x = vector(10 000);

	see(0);
	print ("0 0");

	for (n=1, #x,
		see(v=avoid(x[n]));
		print (n " " v);
		if (n+v <= #x,
			x[n+v] = bitor(x[n+v], v);
		);
	);
}

quit