riemann function from $[0,1]$ Riemann function $f:[0,1] \to \mathbb R$
\begin{eqnarray}
f(x)= \begin{cases} 0&\quad\text {if } x \in \mathbb R - \mathbb Q \cr 
1\over q&\quad\text{if } x = \frac{p}{q} \in \mathbb Q  \cr  \end{cases}
\end{eqnarray}
To $f(x)$: in the upper case, $x=0$ is also possible, lower case $p,q∈N$, largest common factor is $1$. Didn't know how to edit that in.
Show that $f(x)$ is riemann integrable over $[0,1]$ and that the result is $0$.
I tried to work on it but I couldnt get it to even riemann integrable
 A: The condition that the largest common factor of $p$ and $q$ is $1$ is commonly written as $(p,q) = 1$.
As suggested, you can apply the Lebesgue criterion which states that a function is Riemann integrable if and only if the set of discontinuity points has measure $0$. In this case, you would first show that $f$ is continuous at the irrational points in $[0,1]$. It also turns out that this function is discontinuous at every rational point in $[0,1]$, but such points form a countable set of measure zero. The heavy lifting of proving integrability is just relegated then to the big, general theorem of Lebesgue.
A more instructive approach is to consider the behavior of this specific function and show that it is integrable using only the basic concepts pertaining to lower and upper sums.  I assume you have learned that a function is Riemann integrable if the upper and lower sums become arbitrarily close as the partition mesh (length of longest subinterval) goes to $0$. We can do better and show the integral is $0$ by showing that for any partition the corresponding lower sum is $0$, and if the mesh goes to zero the upper sum can be made arbitrarily close to $0$.
Consider any partition $P = (x_0,x_1, \ldots,x_n)$ of $[0,1]$.  Each subinterval $[x_{j-1},x_j]$ must contain an irrational number where $f(x) = 0$. Hence, the greatest lower bound is $m_j = \inf_{x \in [x_{j-1},x_j]}f(x) = 0$ and 
$$L(P,f) = \sum_{k=1}^n m_j \,(x_j - x_{j-1}) = 0.$$
Now consider an upper sum with $M_j = \sup_{x \in [x_{j-1},x_j]}f(x)$,
$$U(P,f) = \sum_{k=1}^n M_j \,(x_j - x_{j-1}).$$
Given $\epsilon > 0$, choose an integer $N > 2/\epsilon$ so that $1/N < \epsilon/2$. Consider all rational points $r = p/q$ in $(0,1]$ with $(p,q) = 1$ and $f(r) = 1/q \geqslant 1/N$. Such points lie in the set
$$S_N = \{p/q \in (0,1]: (p,q) = 1, \,q \leqslant N \}$$
where the number of points in $S_N$ must be some finite integer $M$.  
For example we have $M = 6$ for $S_4 = \{1, 1/2, 1/3, 2/3, 1/4, 3/4\}$.
Choose a partition $P$ with mesh $\|P\| = \max_{j}(x_j - x_{j-1}) < \epsilon/4M.$ There are at most $2M$ subintervals that contain points in $S_N$. On these subintervals $M_j \leqslant 1$ since $f(x) \leqslant 1 $ for all $x \in [0,1]$, and the contribution to the upper sum satisfies
$$\sum_{[x_{j-1},x_j] \cap S_N \neq \phi} M_j \, (x_j- x_{j-1}) < 2M \|P\| < \frac{\epsilon}{2}.$$
On the remaining subintervals which do not intersect $S_N$ we have only rational points where $q > N$ and $M_j < 1/N < \epsilon/2.$ The contribution to the upper sum satisfies
$$\sum_{[x_{j-1},x_j] \cap S_N = \phi} M_j \, (x_j- x_{j-1}) < \frac{\epsilon}{2}\sum_{[x_{j-1},x_j] \cap S_N = \phi}  (x_j- x_{j-1}) < \frac{\epsilon}{2}.$$
Adding the contributions we find $U(P,f) < \epsilon$.  
Thus for any $\epsilon >0 $ we have a partition $P$ such that 
$$0 = L(P,f) \leqslant \int_0^1 f(x) \, dx \leqslant U(P,f) < \epsilon,$$
and, since $\epsilon $ can be arbitrarily small, $f$ is Riemann integrable with
$$\int_0^1 f(x) \, dx = 0.$$
A: Note that there are only finitely many $x \in [0,1]$ such that $f(x) \geq \frac{\epsilon}{2}$ (exercise!). If there are $q$ such $x$, we can enumerate them $x_1, x_2, x_3 \cdots x_q$ and choose a partition $P$ of $[0,1]$ such that each $x_i$ is in  the interior of a subinterval of length smaller than $\frac{\epsilon}{2q}$.  The total length of the $x_i$ containing subintervals is at most $\frac{\epsilon}{2}$ and hence, since $f(x) \leq 1$, the upper sum over these subintervals is at most $\frac{\epsilon}{2}$. 
On the other subintervals we have $f(x)< \frac{\epsilon}{2}$. Moreover, the length of these subintervals is at most $1$, since we're working on $[0,1]$. Hence the upper sum on these subintervals (wrt this partition $P$) is at most $\frac{\epsilon}{2}$. 
This implies over all of $[0,1]$ we have $U(f, P) <\epsilon$. Since the lower sums are all zero trivially the proof is complete. 
