proving a modification of Dirichlet function has a bounded variation I was asked if $f\in BV(0,1)$ ($f$ has a bounded variation) when $f$ is defined as follows:
$$f(x)= \begin{cases}
\frac{1}{n^2 m^2},  & \text{if $x=\frac{m}{n}\in\mathbb{Q}$ with $m,n\in \mathbb{N},gcd(m,n)=1 $}\\
0, & \text{if $ x \notin\mathbb{Q}$ }  \\
\end{cases}
$$
Any help would be much appreciated.
 A: Let $x_1<x_2<x_3< \ldots <x_n$ be a finite sequence in $]0,1[$. Denote by $v$ the total variation
of $f$ along this sequence :
$$
v=\sum_{k=1}^n |f(x_{k+1})-f(x_k)| \tag{1}
$$
Some of the $x_i$ are rational (of the form $\frac{p_i}{q_i}$), others are irrational. Denote by $a$ the least common  denominator of all the denominators appearing among those fractions (or simply set $a=1$ if there is no rationals among the $x_i$).
Then any rational $x_i$ can be written $\frac{t_i}{a}$, where $t_i$ is a positive integer. Then $f(x_i)=\frac{1}{t_i^2a^2} \leq \frac{1}{a^2}$. Since $f(x)=0$ when $x$ is irrational, we deduce
$$
\forall k, \ \   0 \leq f(x_k) \leq \frac{1}{a^2} \tag{2}
$$
Denote by $I$($J$) the set of indices between $1$ and $n$ such that $x_k$ ($x_{k+1}$) is rational. If $k$ is outside $I \cup J$, then $f(x_k)$ and $f(x_{k+1})$ are both zero, so the contribution
$ |f(x_{k+1})-f(x_k)|$ in (1) is zero. So only the contributions with index in $I$ or $J$ matter : 
$$
v=\sum_{k \in I\cup J} |f(x_{k+1})-f(x_k)| \tag{3}
$$
Now for each $k\in I$, $x_k$ is of the form $\frac{t}{a}$ for some integer $t$ between $1$
and $a$. Since there at most $a$ possible values for $t$, we see that $|I| \leq a$, and similarly
$|J| \leq a$. So we deduce from (3) that
$$
v\leq \sum_{k \in I\cup J}^n \frac{1}{a^2} \leq \frac{|I \cup J|}{a^2} \leq \frac{|I| +|J|}{a^2} 
\leq \frac{a +a}{a^2} \leq \frac{2}{a} \leq 2  \tag{4}
$$
So $f$ has bounded variation, and its total variation is at most $2$.
