# Relation between the numbers of units, square roots of unity and divisors for the rings $\mathbb{Z}/n\mathbb{Z}$

For the non-prime numbers $$n$$ up to $$20$$ I listed the number of units of $$\mathbb{Z}/n\mathbb{Z}$$, the number of square roots of unity of $$\mathbb{Z}/n\mathbb{Z}$$ and the number of divisors of $$n$$.

$$\begin{array}{c|c|c} \# & \text{units} & \text{square roots of unity} & \text{divisors} \\ \hline 4 & 2 & 2&3\\ \hline 6 & 2 & 2&4\\ \hline 8 & 4 &4 &4\\ \hline 9 & 6 & 2&3\\ \hline 10 & 4 & 2&4\\ \hline 12 & 4 & 4&6\\ \hline 14 & 6 & 2&4\\ \hline 15 & 8 & 4&4\\ \hline 16 & 8 & 4&5\\ \hline 18 & 6 & 2&6\\ \hline 20 & 8 & 4&6\\ \hline \end{array}$$

The number of units is just $$\varphi(n)$$ (Euler's totient function), i.e. the number of numbers $$m < n$$ that are relatively prime to $$n$$.

But I don't see the correlation pattern between the numbers: How do the numbers of units, square roots of unity and divisors relate for general $$n$$?

Or more generally: Are there expressions for the number of square roots of unity and for the number of divisors (like for the number of units = $$\varphi(n)$$)?

• What do you mean by a "root of unity"? Every unit is a root of unity. – Slade Dec 14 '18 at 12:18
• I think your counts of roots of unity are not consistent. – Slade Dec 14 '18 at 12:22
• I must have understood something wrong: in my understanding $3$ is a unit of $\mathbb{Z}/20\mathbb{Z}$ because $3\cdot 7 \equiv 1 \pmod {20}$, but it's not a root of unity because $3\cdot 3 \not \equiv 1 \pmod {20}$. The units of $\mathbb{Z}/20\mathbb{Z}$ are $1,3,7,9,11,13,17,19$ while the roots of unity are $1,9,11,19$. So every root of unity is a unit but not vice versa. Who of us is wrong? – Hans-Peter Stricker Dec 14 '18 at 12:34
• Ah, I see: I forgot to mention that I meant square roots of unity. I edited the question. – Hans-Peter Stricker Dec 14 '18 at 13:02

The number of divisors of $$n$$ is usually considered to be a primitive function in number theory, so there is most likely not a formula in terms of something simpler. However, if $$n$$ has prime factorization $$\prod_i p_i^{a_i}$$, we can write $$d(n) = \prod_i (a_i + 1)$$.

The total number of roots of unity in $$\mathbb{Z}/n\mathbb{Z}$$ is just $$\varphi(n)$$, since every unit is a root of unity of some order.

If $$n$$ is $$2$$, $$4$$, a power of an odd prime, or twice a power of an odd prime, then the units of $$\mathbb{Z}/n\mathbb{Z}$$ are a cyclic group of order $$\varphi(n)$$, so the number of generators is $$\varphi(\varphi(n))$$, which counts the number of primitive roots of unity. For all other $$n$$, the group of units is not cyclic and there are no primitive roots of unity.

EDIT: The question has changed to ask about square roots of unity.

In general, the structure of the group of units is known, as a decomposition into cyclic groups. See, for example, Wikipedia. From this, you can see how many square roots of unity there are.

I'll summarize the result. Write $$n=2^a m$$, where $$m$$ is an odd integer. Then, the number of square roots of unity in $$\mathbb{Z}/n\mathbb{Z}$$ is $$2^{k+l}$$, where $$k$$ is the number of prime factors of $$m$$, and $$l$$ is $$0$$ if $$a\leq 1$$, $$1$$ if $$a=2$$, and $$2$$ if $$a\geq 3$$.

In $${\Bbb Z}_n$$, $$n\geq 2$$, the number of units plus the number of zero divisors is $$n-1$$, where $$0$$ is not considered as a zero divisor. The reason is that for each $$0\ne a\in{\Bbb Z}_n$$, if $$\gcd(a,n)=1$$, then $$a$$ is a unit; otherwise, $$a$$ is a zero divisor.

These functions are quite complicated due to being combinatorial in nature. Part of the Wikipedia page

https://en.m.wikipedia.org/wiki/Root_of_unity_modulo_n

on roots of unity modulo $$n$$ which is a good place to start is reproduced below.