Continuity of a dirichlet kind of function. Let $f: [0,1] \to \mathbb{R} $ be
$$ f(x) = \left\{
     \begin{array}{lr}
       \frac{1}{q} & : x = \frac{p}{q} \in \mathbb{Q} ,\; \gcd(p,q)=1\\
       0 & : x \notin \mathbb{Q}
     \end{array}
   \right. $$
Claim: $f$ is continuous at $x$ iff $x \notin \mathbb{Q}$
My try: Suppose $f$ is continuous at $x$, and say, by contradiction, that $x \in \mathbb{Q}$. Since $f$ is continous at $x$, then for any $x_n \to x $, we must have $f(x_n) \to f(x)$. Consider $x_n = x + \frac{ \sqrt{2}}{n} \to x$. But, $f(x_n) = 0 \neq 1 = f(x)$. Contradiction, hence $x \notin \mathbb{Q}$. 
Conversely, if $x \notin \mathbb{Q}%$, then $f(x) =0 $ which is trivially continuous.
IS this correct?
 A: (1) $f$ is continuous for the irrational numbers. 
Let $a$ be an irrational number. Given $\varepsilon>0$, choose $1/n< \varepsilon$ and define  $K= \lfloor an\rfloor$, so $K/n<a<(K+1)/n$, i.e., $a\in \left(\frac{K}{n},\frac{K+1}{n}\right)$. 
We claim that in $\left(\frac{K}{n},\frac{K+1}{n}\right)$ there  can be at most one number of the form $p/m$ for $m\le n$.  Suppose to the contrary that for some  $m\le n$ we have $\frac{r}{m}, \frac{s}{m}\in \left(\frac{K}{n},\frac{K+1}{n}\right)$ and $r/m\not= s/m$. Then 
$$\frac{|r-s|}{m}<\frac{1}{n}$$
$$\frac{1}{m}<\frac{1}{n}$$
So $n<m$, a contradiction. In particular this implies that we have a finite number of rationals $\frac{p}{q} \in\left(\frac{K}{n},\frac{K+1}{n}\right)$ in  the reduced form such that $q\le n$.  Denote these numbers  $p_1,\ldots p_k $. We choose $\delta = \min\{|a-p_i|: i=1,\ldots k\}$. 
Now we claim that for $|x-a|<\delta$ we have  $|f(x)|< \varepsilon$. If $x$ is irrational the result is trivial. Suppose that $y$ is rational. It will suffice to show that $y$ is not in the form $p/q$ for $q\le n$, if were such the case, we have that $y= p_j$ for $j\in \{1, \ldots k\}$ and so  $|p_j-a|< \delta\le |p_j-a|$, a contradiction. So if $y= p/q$ form, $q>n$ and so $f(x)=1/q<1/n<\varepsilon$. Combining these two cases we see that $|f(x)-f(a)|= |f(x)|< \varepsilon$, as desired. 
(2) $f$ is not continuous for the rational numbers.
Suppose for sake of contradiction that $a= p/q$ in reduced form and $f$ is continuous at $a$. Let $\varepsilon = 1/q$ so by definition of continuity there is a $\delta > 0$ such that $|f(x)-f(a)|=|f(x)-1/q|<\varepsilon$ whenever $|x-a|<\delta$. Let $x$ be an irrational number then $|f(x)-1/q|=1/q< \varepsilon=1/q$, a contradiction.
