Let $P$ be a prime ($>2$) and $g$ a value between $2$ and $P-2$.
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= \frac{P (P-1)}{2}$$
Is there also a formula for values $g$ not a prime root of $P$? Especially $g$ has order of $k$ with $k$ a prime.
The set $M$ can also be written as: $$M_k = \{g^n\bmod P, \text{ with } 0 < n \le k \}$$ $$1 \equiv g^k \bmod P$$ For any $g$ exists an exponent $k$ which is limited to the factors of the factorization of $P-1$ or products out of those prime values, so the order of $g$ is $k$.
Main question: What is exact sum of such a subset with $k$ a prime greater than $2$ (and given suitable $g$)?
Partly solution:
During testing around I noticed one factor of this sum $S$ seems to be $P$.
So
$$ S = \sum M_k = c \cdot P$$
Any way to calculate this factor $c$?
I did some related question in cryptography stack. There only a partly answer was given for even $k$ which is $c=k/2$ and only an approximation for odd $k$ which is $c\approx k/2$. But I'm interested in prime values of $k$ and an exact solution. I did some new post here because I think the mathematical expertise is higher here and some answer to this might be known.
Example: $g=13, P=23$
With $g=13$ only half the numbers out of $\mathbb{Z}/23\mathbb{Z}$ can be generated:
$M_{11} = \{13,8,12,18,4,6,9,2,3,16,1\}$
sum $S=\sum M_{11} = 92$, which is $4 \cdot P$
Why $4$ times? Any way to compute this factor?