Let $r_2(n)$ denote the number of representations of $n$ as a sum of 2 squares. It is well-known that $$r_2(n) = 4\sum_{d \mid n} \chi(d),$$ where $\chi$ is the non-principal character modulo $4$.
My question is: Are there other examples of characters appearing in a naturally occurring arithmetic function?
And what really interests me - Does it ever happen that a non-real character appears?