a(n) = {
	\\ u=least term unseen, m=mask of substrings seen so far
	my (u=1, m=0);
	\\ w=binary width
	for (w=1, oo,
		\\ s=fractions seen so far
		my (s=Set(), f=1/max(n,2));
		while (!setsearch(s,f),
			my (v=floor(f*2^w));
			if (!bittest(m,v),
				\\ new term
				m+=2^v;
				while (bittest(m,u), u++);
			);
			s=setunion(s,Set(f));
			f=frac(f*2);
		);
		\\ at this point we have all terms up to 2^w-1
		if (u!=2^w,
			return (u-1);
		);
	);
}

\\ a(2*n) = a(n)
cache = vector(5 000)
for (n=1, 10 000, cache[n] = if (n%2, a(n), cache[n/2]); print (n " " cache[n]))

quit