Characterization of two sets I am  interested in the following problem:
Let $n \in \mathbb{N} $ . We define the function $S_n: \mathbb{Z_n^*} \to \mathbb{Z_n} $
\begin{align} S_n(\bar a) := \bar 1  + \bar a + \bar a^2 + ...+ \bar a^{\left(ord_na\right)-1} \in \mathbb{Z_n} \end{align}
where $\mathbb{Z_n^*}$ are the invertible elements of $\mathbb{Z_n}$ and $ord_na$ the order of $a$(mod($n$)). 
Some pretty obvious results are:


*

*$S_n(\bar 1)$ = $\bar 1$  $\forall n \in \mathbb{N^*} $

*$S_n(\overline {-1} )$ = $\bar 0$  $\forall n \in \mathbb{N^*} $

*$S_n(\bar a) = \bar 0$  $\forall \bar a,n$ : $ \overline {1-a} \in \mathbb{Z_n} $ is invertible. That is to say $gcd(1-a,n)=1$. 
That holds because $(1+a + a^2 + ... + a^{ord_n(a)-1})(1-a)=1-a^{ord_n(a)}\equiv 0$ $mod(n)$ 


*$S_p(\bar a) = \bar 0 $  $\forall \bar a \in \mathbb{Z_p^*} - \{\bar 1 \} $, when $p$ is prime


To prove that, notice that $\mathbb{Z_p^*}=\{ \bar 1, \bar 2, ..., \overline{p-1} \}$, so $\overline{1-a} \in \mathbb{Z_p^*} $ $\forall \bar a \in \mathbb{Z_p^*} - \{\bar 1 \} $


*If $\mathbb{Z_n^*}$ is cyclic (that is to say $n=2,4, p^m$ or $2p^m$ for some $p$ prime and $m$ natural) and $ord_n(a) = |\mathbb{Z_n^*} | =\phi (n) $, then $S_n(\bar a)=\bar 0 $


This is true because $S_n(\bar a) = \sum_{i=1}^{i=\phi(n)} \bar a ^ i = \sum_{\bar b \in \mathbb{Z_n^*}} \bar b = \bar 0 $ (if $\bar a \in \mathbb{Z_n^*}$ then $\overline {-a} \in \mathbb{Z_n^*}$ and $\bar a \neq \overline{-a}$ because  $\bar a$ invertible. So $\mathbb{Z_n^*}$ comes in pairs $\bar a$, $\overline{-a}$ )


*$S_n(\bar a) \notin \mathbb{Z_n^*}$ $\forall \bar a \in \mathbb{Z_n^*} - \{\bar 1 \}$


For this, notice that, in the relation in 3. , if  $S_n(\bar a)$ is invertible, $1-a \equiv 0$ $mod(n)$
However, 4. doesn't generally hold if $p$ is not a prime. For example, $S_8(\bar 3) = \bar 4$. That is not to say that it necessarily  does not hold. For example, for $n=6$, $\mathbb{Z_p^*}=\{ \bar 1, \bar 5\}$ and $S_6(\bar 5) =\bar 0$ (See 2.) And there are not trivial examples as well, let's say $n=10$, where property 4. holds.
So, the first natural question is whether we can find a characterization for the sets 
\begin{align} A_n:=\{ \bar a \in \mathbb{Z_n^*} : S_n(\bar a) = \bar 0 \} \end{align} 
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 continue defining 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. 
Result 4. from above implies $S(p)= \bar 1$. If $p$ is not a prime this does not generally hold, $S(8) =\bar 3 $ and $S(9)= \bar 7 $. Interestingly, both of those (and many more for that matter) are invertible. However, this is not generally the case (!). For example $S(12)=\bar 3$ 
This bring us to a 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.
 A: There will not be any simple description of these sets, even in some simple cases.
For example, let $p > 3$ be prime, let $n = 9p$, and let $a = 4$.
The problem becomes characterizing the primes $p$ for which $4$ mod $p$ (or equivalently, $2$ mod $p$) has order divisible by $9$. If $p \equiv 1$ mod $9$ but $p \not\equiv 1$ mod $27$, this is the same as asking that $2$ is not a cube modulo $p$. But there is no simple description of this set. It is certainly equal to the set of primes (with the given congruence conditions) which do not split completely in the field
$$x^3 - 2.$$
However, since the splitting field of this polynomial is not abelian, there will not be any congruence conditions on $p$ which determine when this property holds (as follows from class field theory). So roughly, the answer to your problem even in the simple triple $(n,a) = (9p,4)$ does not admit a simple answer. Similarly, if $p \equiv 1$ mod $27$ and not $1$ mod $81$, the problem becomes one of determining when $2$ is a $9$th power modulo $p$ or not, and if $p \equiv 1$ mod $3^n$ and not $1$ mod $3^{n+1}$, it's a question of whether $2$ is a $3^{n-1}$th power or not. These  "characterizations" do not really admit a simple description, and are really just reformulations of the original question.
