Below we discuss some problem about Ramanujan’s sum.
Problem 1. Let us denote $e(\alpha) = e^{2 \pi i \alpha}$. Show that
\[
\frac{1}{q}\sum_{a = 1}^{q} e \left( \frac{an}{q} \right) =
\begin{cases}
1 & \text{if $q \, | \, n$}, \\
0 & \text{otherwise}.
\end{cases}
\]
Solution. Note that if $q \, | \, n$, then $e(an/q) = 1$ for every $1 \leq a \leq q$ and so we have
\[
\frac{1}{q} \sum_{a = 1}^{q} e(an/q) = \frac{1}{q} \sum_{a = 1}^{q} 1 = 1.
\] Now suppose that $q \hspace{-2pt} \nmid \hspace{-2pt} n$. Then we have $e(n/q) \neq 1$ and so
\[
\frac{1}{q} \sum_{a = 1}^{q} e(an/q) = \frac{1}{q} \sum_{a = 1}^{q} e(n/q)^a = \frac{1}{q} \left( \frac{e(n/q)^{q+1} -1}{e(n/q) -1} -1 \right) = 0
\]as $e(n/q)^{q+1} = e(n/q)$.
Problem 2. The Ramanujan’s sum $c_q(n)$ is defined as
\[
c_q(n) = \sum_{\scriptstyle a = 1 \atop \scriptstyle (a, q) = 1}^{q} e \left( \frac{an}{q} \right).
\] Show that
\[
c_q(n) = \sum_{d \, | \, (n, q)} d \mu\left( \frac{q}{d} \right).
\] Deduce that
\[
\mu(q) = \sum_{\scriptstyle a =1 \atop \scriptstyle (a, q) = 1}^{q} e \left( \frac{a}{q} \right).
\]
Solution. Observe that
\[ \begin{align} c_q(n) &= \sum_{\scriptstyle a = 1 \atop \scriptstyle (a, q) = 1}^{q} e \left(\frac{an}{q} \right) = \sum_{a = 1}^{q} e\left(\frac{an}{q} \right) \sum_{d \, | \, (a, q)} \mu(d) = \sum_{a = 1}^{q} e \left(\frac{an}{q} \right) \sum_{\scriptstyle d \, | \, a \atop \scriptstyle d \, | \, q} \mu(d). \end{align}
\]Changing the order of summation we get
\[ \begin{align} c_q(n) &= \sum_{d \, | \, q} \mu(d) \sum_{\scriptstyle a = 1 \atop \scriptstyle d \, | \, a}^{q} e\left(\frac{an}{q} \right) = \sum_{d \, | \, q} \mu(d) \sum_{r = 1}^{q/d} e\left(\frac{rdn}{q} \right) = \sum_{d \, | \, q} \mu(d) \sum_{r = 1}^{q/d} e\left(\frac{rn}{q/d} \right). \end{align} \] Thus we can rewrite $c_q(n)$ as
\[
c_q(n) = \sum_{d \, | \, q} \mu \left( \frac{q}{d} \right) \sum_{r = 1}^{d} e \left( \frac{rn}{d} \right).
\] Using the identity $\frac{1}{q}\sum_{a = 1}^{q} e(an/q) = \mathbf{1}_{q \, | \, n}$ we end up with
\[
c_q(n) = \sum_{\scriptstyle d \, | \, q \atop \scriptstyle d \, | \, n} d\mu \left( \frac{q}{d} \right) = \sum_{d \, | \, (q, n)} d \mu \left( \frac{q}{d} \right).
\] Finally, note that
\[
\mu(q) = c_q(1) = \sum_{\scriptstyle a = 1 \atop \scriptstyle (a, q) = 1}^{q} e \left( \frac{a}{q} \right).
\]
Problem 3. Let $\ell =(n, q)$. Show that
\[
c_q(n) = \mu \left( \frac{q}{\ell} \right) \varphi(q) \varphi \left( \frac{q}{\ell} \right)^{-1}.
\]
Solution. Note that
\[
c_q(n) = \sum_{d \, | \, \ell} d \mu \left( \frac{q}{d} \right) = \sum_{d e = \ell} d \mu \left( \frac{qe }{\ell} \right).
\] Let $q_1 = q/\ell$. Then observe that $\mu(q_1 e) = 0$ if $(q_1, e) \neq 1$ and $\mu(q_1 e) = \mu(q_1) \mu(e)$ if $(q_1, e) = 1$. Using this we get
\[
c_q(n) = \sum_{d e = \ell} d \mu(q_1 e) = \sum_{\scriptstyle de = \ell \atop \scriptstyle (q_1, e) = 1} d \mu(q_1) \mu(e) = \mu(q_1) \sum_{\scriptstyle de = \ell \atop \scriptstyle (q_1, e) = 1} d \mu(e) = \mu(q_1) \ell \sum_{\scriptstyle de = \ell \atop \scriptstyle (q_1, e) = 1} \frac{\mu(e)}{e}.
\] It is easy to see that
\[\begin{align} \sum_{\scriptstyle e \, | \, \ell \atop \scriptstyle (e, q_1) = 1} \frac{\mu(e)}{e} &= \prod_{\scriptstyle p \, | \, \ell \atop \scriptstyle p \, \nmid \, q_1} \left( 1 -\frac{1}{p} \right) = \prod_{\scriptstyle p \, | \, q \atop \scriptstyle p \, \nmid \, q_1} \left( 1 -\frac{1}{p} \right) \\ &= \prod_{p \, | \, q} \left( 1 -\frac{1}{p} \right) \cdot \prod_{p \, | \, q_1} \left( 1- \frac{1}{p} \right)^{-1} \ \\ &= \frac{\varphi(q)}{q} \cdot \frac{q_1}{ \varphi(q_1)} = \frac{\varphi(q)}{\ell \varphi(q_1)}. \end{align}
\] Hence we have
\[
c_q(n) = \mu(q_1) \ell \cdot \frac{\varphi(q)}{\ell \varphi(q_1)} = \mu(q_1) \varphi(q) \varphi(q_1)^{-1}.
\]
Problem 4. Prove that
\[
\sigma(n) = \frac{\pi^2 n}{6} \sum_{q = 1}^{\infty} \frac{c_q(n)}{q^2}.
\]
Solution. We rewrite $\sigma(n)$ as
\[
\sigma(n) = n\sum_{d \, | \, n} \frac{1}{d} = n\sum_{d = 1}^{n} \frac{1}{d} \left( \frac{1}{d} \sum_{a = 1}^{d} e(an/d) \right) = n \sum_{d = 1}^{n} \frac{1}{d^2} \sum_{a = 1}^{d} e(an/d)
\] since $\frac{1}{d}\sum_{a = 1}^{d} e(an/d)$ is the characteristic function of the divisors of $n$. Because $\sum_{a = 1}^{d} e(an/d) = 0$ for $d > n$, we can extend the above finite sum to an infinite sum as
\[
\sigma(n) = n \sum_{d = 1}^{\infty} \frac{1}{d^2} \sum_{a = 1}^{d} e(an/d). \tag{1}
\] Observe that
\[\begin{align} \sum_{a = 1}^{d} e(an/d) &= \sum_{q \, | \, d} \sum_{\scriptstyle a = 1 \atop \scriptstyle (a, d) = q}^{d} e(an/d) = \sum_{q \, | \, d} \sum_{\scriptstyle r = 1 \atop \scriptstyle (r, d/q) = 1}^{d/q} e(rqn/d) \\ &= \sum_{q \, | \, d} \sum_{\scriptstyle r = 1 \atop \scriptstyle (r, d/q) = 1}^{d/q} e(rn/(d/q)) = \sum_{q \, | \, d} c_{d/q}(n) = \sum_{q \, | \, d} c_q(n). \end{align}
\] Substituting this into (1) we obtain
\[
\sigma(n) = n \sum_{d = 1}^{\infty} \frac{1}{d^2} \sum_{q \, | \, d} c_q(n) = n \sum_{d = 1}^{\infty} \sum_{q \, | \, d} \frac{c_q(n)}{d^2}.
\] Changing the order of summation, we get
\[\begin{align} \sigma(n) &= n \sum_{q = 1}^{\infty} \sum_{\scriptstyle d = 1 \atop \scriptstyle q \, | \, d}^{\infty} \frac{1}{d^2} c_q(n) = n \sum_{q = 1}^{\infty} \sum_{\ell = 1}^{\infty} \frac{c_q(n)}{(q \ell)^{2}} \\ &= n \sum_{q = 1}^{\infty} \sum_{\ell = 1}^{\infty} \frac{1}{\ell^{2}} \frac{c_q(n)}{q^{2}} = n \left( \sum_{\ell = 1}^{\infty} \frac{1}{\ell^{2}} \right) \sum_{q = 1}^{\infty} \frac{c_q(n)}{q^2} \\ &= \frac{n \pi^2}{6} \sum_{q = 1}^{\infty} \frac{ c_q(n)}{q^{2}}, \end{align}
\] where we use $\sum_{k = 1}^{\infty} 1/k^2 = \pi^2/6$ in the final equality. The change of order of summation is justified by the fact that $c_q(n) \ll_n 1$ and $d(n) \leq \sqrt{n}$.