This post has similar condition and objects of that post .
When I am doing my study, I found that for arbitrary positive integer $a,m$. Let $\mathbf{S}=\{ a^{n} \bmod m : n \in \mathbb{Z}^{+} \}$. Obviously, $\mathbf{S}$ is a finite set.
Is it possible to write an algebraic expression of the cardinality of $\mathbf{S}$ when $a,m$ are specified?