big = 1 000 000
s = 0
S = []
unseen = 1
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++)

\\ least k unseen / p AND k != 0
look(p) = {
	for (v = unseen, oo,
		if (!seen(v) && bitand(p, v)!=0,
			return (v);
		);
	);
}

n = 0
a = vector(5000)
emit(v) = {
	print (n++-1 " " v);
	see(v);
	if (n <= #a,
		a[n] = v;
	);
}

{
	emit(0);
	emit(1);
	for (n = 2, #a,
		emit(v = look(a[n]));
		emit(look(bitand(v, a[n])));
	);
}

quit