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)$)?
 A: 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$.
A: 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. 
A: 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.

