Let $P$ be a prime and $g$ a value between $2$ and $P$.
Let $M$ be the set of numbers which can be generated with $g$:
$$M = \{g^n\bmod P, \text{ with } 0 < n <P \}$$
If $g$ is a prime root of $P$ all values $1$ to $P-1$ can be generated.
The sum of those would be:
$$S=\sum M = \sum_{n=1}^{P-1} (g^n \bmod P) = \sum_{n=1}^{P-1} n= (P/2)\cdot (P-1)$$
Is there also a formula for values $g$ not a prime root of $P$?
(So for generators $g$ which are only able to generate a subset of $\mathbb{Z}/p\mathbb{Z}$)
Question: What is exact sum of such a subset?
Partly solution:
During testing around I noticed one factor of this sum $S$ seems to be $P$.
So
$$ S = \sum M = c \cdot P$$
and with this
$$ 0 \equiv S \bmod P$$
Is that always the case? EDIT: seems to be the case, see comment from runway44 (edit end)
Any way to calculate this factor $c$?
Example: $g=13, P=23$
With $g=13$ only half the numbers out of $\mathbb{Z}/23\mathbb{Z}$ can be generated:
$M = \{13,8,12,18,4,6,9,2,3,16,1\}$
sum $S=\sum M = 92$, which is $4 \cdot P$
Why $4$ times? Any way to compute this factor?