Problem: Consider the function $f $ on $[0,1]$ defined as
\[
f(x) =
\begin{cases}
\frac{1}{n}, &\text{ if } \frac{1}{n+1} \leq x \leq \frac{1}{n} ;\\
0, &\text{ if } x = 0.
\end{cases}
\]
Prove that $f$ is integrable on $[0,1] $. If $\displaystyle \sum_{n} \frac{1}{n^2} = \frac{\pi ^2}{6}$, then evaluate the integral $\displaystyle \int_0^1 f(x) \mathrm{d} x$.
Solution: Look at the graph of the function
\[
f(x) =
\begin{cases}
\frac{1}{n}, &\text{ if } \frac{1}{n+1} \leq x \leq \frac{1}{n} ;\\
0, &\text{ if } x = 0.
\end{cases}
\]
Since $0\leq f(x) \leq 1$, so $f$ is bounded and it is continuous on $[0,1]$ except at $x = \frac{1}{n},$ for $n = 2,3,\dots$. The set of discontinuity of $f$ is countable, so $f$ is Riemann integrable (we could have also used the fact that the set of discontinuity of $f$ is infinite with one limit point $0$, so $f$ is integrable).
Now we need to find the integral. Let us write
\[
f_n(x) = \frac{1}{n},\quad \frac{1}{n+1} \leq x \leq \frac{1}{n}, n \in \mathbb{N} .
\]
Then,
\begin{align*}
\int _0^1 f(x) & = \lim_{n \to \infty} \left[ \int _{\frac{1}{2}}^1 f_1(x) + \int _{\frac{1}{3}} ^{\frac{1}{2}} f_2(x) + \dots + \int_{\frac{1}{n+1}^{\frac{1}{n}}}f_n(x) \right] \\[2ex]
& = \lim_{n \to \infty} \left[ 1 \left( 1-\frac{1}{2} \right) + \frac{1}{2}\left( \frac{1}{2} - \frac{1}{3} \right) + \dots + \frac{1}{n}\left( \frac{1}{n} - \frac{1}{n+1} \right) \right] \\[2ex]
& = \lim_{n \to \infty} \left[ \sum_{i=1}^{n} \frac{1}{i^2} - \sum_{i=1}^{n} \frac{1}{i\cdot (i+1)} \right] \tag{$\star $}.
\end{align*}
We note that
\begin{align*}
\sum_{i=1}^{n} \frac{1}{i\cdot (i + 1)} & = \sum_{i=1}^{n} \left( \frac{1}{i} - \frac{1}{i+1} \right) = 1 - \frac{1}{n+1}.
\end{align*}
Substituting this in $(\star)$, we get
\begin{align*}
\int _0^1 f(x) & = \lim_{n \to \infty} \left[ \sum_{i=1}^{n} \frac{1}{i^2} - \sum_{i=1}^{n} \frac{1}{i\cdot (i+1)} \right] \\
& = \lim_{n \to \infty} \left[ \sum_{i=1}^{n} \frac{1}{i^2} - \left( 1 - \frac{1}{n+1} \right) \right] \\
& = \lim_{n \to \infty} \sum_{i=1}^{n} \frac{1}{i^2} - 1 \\
& = \frac{\pi ^2}{6} - 1.
\end{align*}
Thus,
\[
\textcolor{teal}{\boxed{
\int _0^1 f(x) = \frac{\pi ^2}{6} - 1
}}
\]