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

Let $R$ be a ring. An element $x$ in $R$ is said to be idempotent if $x^2=x$. For a specific $n\in{\mathbb Z}_+$ which is not very large, say, $n=20$, one can calculate one by one to find that there are four idempotent elements: $x=0,1,5,16$. So here is my question:

Is there a general result which tells the number of the idempotent elements of ${\mathbb Z}_n$?

-
(Number of prime factors)! +2 My observation! –  UNM Aug 11 '13 at 3:31

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?

-
I don't know much about abstract algebra but some basic definitions. I guess the idea is similar/related to the Fundamental Theorem of Finite Abelian Groups, isn't it? –  Jack Jun 16 '11 at 16:43
(I guess you mean the idea of the isomorphism I mentioned?) It is related to that. It is, in fact, a form of the Chinese Remainder Theorem (see Wikipedia, for example) –  Mariano Suárez-Alvarez Jun 16 '11 at 16:45
What do you mean by "counting them in each factor"? Do you mean counting the idempotent elements in each ${\bf Z}_{p_i^{m_i}}$ and then add them up? –  Jack Jun 16 '11 at 16:59
@Jack: I mean that if you know how many idempotents there are in each factor it is not hard to know how many idempotents there are in the product. This follows from the following simple observation: an element $(a,b)$ in a direct product of two rings $A\times B$ is idempotent if and only if $a$ is idempotent in $A$ and $b$ is idempotent in $B$. –  Mariano Suárez-Alvarez Jun 16 '11 at 17:02
Fair enough. Now I see. Thanks! –  Jack Jun 16 '11 at 17:06

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\:.$

-