I got this apparently easy fact in an example in a real analysis textbook, assumed without proof in the solution of some other problem not worth mentioning, but after some effort I think I'm not able to fix the correct ideas to prove it.
Let $f:[a,b]\to \mathbb{R}$ be defined by $f(x) = 0$ if $x$ is irrational or zero and $f\left(\frac{p}{q}\right) = \frac{1}{q}$ if $\frac{p}{q}$ is a irreductible fraction, with $p\ne 0$ (where of course $p$ and $q$ are integers and $q\ne 0$). Then, for $\varepsilon > 0$, the set $F_{\varepsilon} := \left\{ x\in [a,b]: f(x)\ge\varepsilon\right\} $ is finite.
The text says that it is so because $F_a$ is the set of the irreductible fractions of $[a,b]$ whose denominators are $\le\frac{1}{a}$, but after some effort I was not able to show that this set is indeed finite. I assumed it is not, but I don't know how to use the fact that the fractions are irreductible to show the finitude of $F_a$. Any help will be appreciated.
Lemma 1: for every $n \in \Bbb N \setminus \{0\}$, the level set $L_n = \{ x \in [a,b] \mid f(x) = \frac1n \}$ is finite.
Lemma 2: for every $\varepsilon > 0$, the set $\{ n \in \Bbb N \setminus \{0\} \mid \frac 1 n \ge \varepsilon \}$ is finite.
Then you are done, since the set required is just the indexed product of the first sets (each of which is finite) indexed by the second set (which is finite).