How many idempotent elements does the ring ${\bf Z}_n$ contain?

If $n=p_1^{m_1}\cdots p_k^{m_k}$ is the factorization of $n$ as a product of powers of distinct primes, then the ring $\mathbb Z/n\mathbb Z$ is isomorphic to the product $\mathbb Z/p_1^{m_1}\mathbb Z\times\cdots\times \mathbb Z/p_k^{m_k}\mathbb Z$. It is easy to reduce the problem of counting idempotent elements in this direct product to counting them in each factor.

Can you do that?


In $\Bbb{Z}_n$ the relation $x^2=x$ is equivalent to $(x-1)x\equiv 0 ( mod \ n)$, that is $n | x(x-1)$. This is an easy way to calculate all idempotent elements for small $n$. In general, you need to consider the factorization of $n$ in prime factors and note that $x,x-1$ are coprime, and if one prime number divides one of them, it can't divide the other.


HINT $\ $ Idempotents in $\rm\:\mathbb Z/n\:$ are closely related to factorizations of $\rm\:n\:$ into coprime factors, i.e. $\rm\: n = a\:b\:,\:$ where $\rm\:gcd(a,b) = 1\:.\ $ Indeed, notice that $\rm\:p^k\ |\ e\:(e-1)\ \Rightarrow\ p^k\ |\ e\:$ or $\rm\:p^k\ |\ e-1\:.$