s = [];

see(z) = {
	my (n=numerator(z), d=denominator(z));
	if (n > #s,
		s = concat(s, vector(n-#s));
	);
	s[n] += 2^d;
}

seen(z) = {
	my (n=numerator(z), d=denominator(z));
	if (n > #s,
		return (0),
		return (bit test(s[n], d))
	);
}

up(z)   = (1+numerator(z))/   denominator(z)
down(z) =    numerator(z) /(1+denominator(z))

v = 1;
val = vector(10 000);
val[1] = 1;

explore1(z) = {
	if (v < #val && !seen(z),
		v++;
		val[v] = z;
		see(z);
	);
}

explore(z) = {
	explore1(up(z));
	explore1(down(z));
}

{
	see(val[1]);
	for (n=1, #val,
		print (n " " denominator(val[n]));
		explore(val[n])
	)
}

quit