What is wrong with this proof of Riemann Integrability? Consider the so-called Riemann function $f:[0,1]\to\mathbb R$, defined by $$f(x)= \begin{cases}0 & \text{if } x \text{ is irrational or }x=0,\\ \frac1n & \text{if }x=\frac{m}n \text{ where the fraction }\frac{m}n\text{ is irreducible and } n \geq1.\end{cases}$$ Show that the function $f$ is Riemann integrable on $[0,1]$. Show that for given $\epsilon>0$ there exists only finitely many $x\in(0,1]$ such that $x=\frac{m}n$ and $\frac1n\geq\frac{\epsilon}{2(b-a)}$. Use this fact to find $\delta > 0$ such that for every partition P satisfying $\|P\|<\delta$ we have $S(f,P)-s(f,P)<\epsilon$.
Proof:
There are obviously only finitely many n for which $\frac1n\geq\frac{\epsilon}{2(b-a)}$Since the domain is $[0,1]$, we must have $m\leq n$, so only finitely many $m$ exist.$\implies$ Only finitely many $x=m/n$ exist. Let the number of such $x$ be $N$. (I know I need to do something with this, but I don't know what.) Let $P\in\mathcal P([0,1])$, $P=\{x_0,...,x_k\}$. Notice that $$S(f,P)=\sum_{i=1}^k(x_i-x_{i-1})M_i, M_i=\displaystyle\sup_{[x_{i-1},x_i]}f(x)$$
$$s(f,P)=\sum_{i=1}^k(x_i-x_{i-1})m_i,m_i=\inf_{[x_{i-1}-x_i]}f(x)$$
But $m_i=0\ \forall i$ sine there is some irrational number in every interval. So $s(f,P)=0.$ Note that $f(x)\leq 1 \ \forall x\in[0,1]$. Let $\delta = \frac{\epsilon}k.$ Then, if $\|P\| \leq \delta,$$$\begin{split} S(f,P)-s(f,P) & =S(f,P)\\ & =\sum_{i=1}^k(x_{i}-x_{i-1})M_i \\ & \leq \sum_{i=1}^k(x_i-x_{i-1})*1 \\ & \leq k\|P\| \\ & \leq \epsilon.\end{split}$$
I feel that $\delta$ should be related to the number of $\frac mn$'s, and that the spacing of the partition should work out such that the $\frac\epsilon{2(b-a)}$ comes into play, but I don't know how.
 A: I'll work on $[a,b]$ rather than $[0,1].$
For any $\varepsilon > 0$, as you've stated, there are only finitely many rationals $x = m/n$ with $1/n \ge \varepsilon/2(b-a)$. Let $N$ be the number of such rationals, $Q^*$ be the set of such rationals and $P$ be any partition with $\lvert \lvert P \rvert \rvert < \varepsilon/(4N)$. Again, as you've pointed out, we have lower sum $s(f,P) = 0$ for any partition. For the upper sum, we see that since there are only $N$ members of $Q^*$, at most $2N$ panels in $P$ contain a member of $Q^*$ (this 'worst case scenario' would happen if each member of $Q^*$ was an endpoint of an panel in $P$). Since $f(x) \le 1$ and the length of these panels is less than or equal to $\varepsilon/(4N)$, these panels can contribute at most $2N\cdot  \varepsilon/(4N) = \varepsilon /2$ to the upper sum. For the other panels, we have that $f(x) < \varepsilon/2(b-a)$ so the other panels can contribute at most $(b-a) \cdot \varepsilon/2(b-a) = \varepsilon/2.$ Thus the upper sum on such partitions satisfies $S(f,P) \le \varepsilon$. Since $\varepsilon > 0$ was arbitrary, this shows that $f$ is Riemann integrable. 
A: Your error is assuming you can choose a partition of $[0,1]$ with mesh smaller than $\epsilon/k$ where $k$ is the number of subintervals.  The total length of these subintervals is then less than $\epsilon$. For arbitrary $\epsilon < 1$ the partition fails to cover the full interval.
Instead choose a partition with mesh less than $\epsilon/4N$ and for which the number of points exceeds $N$. No more than $2N$ subintervals can contain points where $f(x) > \epsilon/2$, and the contribution to the upper sum is less than $ 1 \cdot 2N \cdot \epsilon/4N = \epsilon/2.$  It is easy to show that the contribution from the remaining subintervals is also less than $\epsilon/2.$
