Solution (source code)

= Solution

Use the unitary <discrete Fourier transform>, with $e(x)=\exp(2\pi ix)$:
$$
\widehat f(a)=q^{-1/2}\sum_{n\bmod q}f(n)e(-an/q).
$$
For a unit $a$, substitute $m=an$ in the sum. The multiplicativity of the <Dirichlet character> gives $\chi(a^{-1}m)=\overline{\chi(a)}\chi(m)$, hence
$$
\boxed{\widehat\chi(a)=\overline{\chi(a)}\widehat\chi(1).}
$$
The <complex conjugation> is present in the original PDF and lost in the converted TeX. It matters for nonreal characters.

Now let $q=p^k$ and let $\chi$ be primitive. Since it does not descend to $p^{k-1}$, there is a unit $u\equiv1\pmod{p^{k-1}}$ with $\chi(u)\ne1$. For $k=1$, reduction is to the unit group modulo one. If $p\mid a$, then $a(u-1)\equiv0\pmod q$, so multiplication of the summation variable by $u$ leaves its exponential factor unchanged. It follows that $\widehat\chi(a)=\chi(u)\widehat\chi(a)$, and therefore $\widehat\chi(a)=0$. Also $\chi(a)=0$. This proves the formula at every nonunit as well as every unit, including $a=0$.