I posted this question on math.SE 10 days ago and had no answer, comment or vote. If an answer is not available, I could really use a reference point as well.
For the sake of completeness, I am restating the essence of my question below, omitting details that can be found on the link above.
I am interested in the following problem:
For $n\in\mathbb{N}$, define the function $S_n:\mathbb{Z_n^*}\to\mathbb{Z_n}$ by $$ S_n(\bar a) := \bar 1 + \bar a + \bar a^2 + ...+ \bar a^{\left(ord_n(a)\right)-1}, $$ where $\mathbb{Z_n^*}$ is the set of all invertible elements of $\mathbb{Z_n}$, and $ord_n(a)$ the order of $a$ modulo $n$.
Can a characterization for the sets $$ A_n:=\{ \bar a \in \mathbb{Z_n^*} : S_n(\bar a) = \bar 0 \} $$
be found?
Now, considering the $\amalg {\mathbb{Z_n} }$ as consisting of the elements $(\bar a, n)$ where $n \in \mathbb{N}$ and $\bar a \in \mathbb{Z_n}$, we define the function $S : \mathbb{N} \to \amalg {\mathbb{Z_n} } $ such as \begin{align} S(n) = \left( \sum_{\bar a \in \mathbb{Z_n^*}} {S_n(\bar a)}, n \right)\end{align} thinking of $S(n)$ as an element of $\mathbb{Z_n}$ when there is no danger of confusion.
This bring us to the second question. Can we find (or know more about) the set \begin{align} A:= \{ n \in \mathbb{N} : S(n) \in \mathbb{Z_n^*} \}\end{align}
Thank you in advance.