square root of $1 \pmod m$ for prime $m$ and non prime $m$ While doing square root $1$ moduli i.e. $x ^2 \equiv 1 \pmod m$ I noticed the following:
If the moduli $m$ is prime it seems that the square is always $1$ and $m - 1$
But if it is not prime, it is not the case and I am not sure if there is a general formula for that.
Examples:
$1 \pmod 3$: $1$ and $2$
$1 \pmod 4$: $1$ and $3$
$1 \pmod 5$: $1$ and $4$
$1 \pmod 6$: $1$ and $5$
$1 \pmod 7$: $1$ and $6$
$1 \pmod 8$: $1$ and $3$ and $5$ and $7$
$1 \pmod 9$: $1$ and $8$
$1 \pmod {11}$: $1$ and $10$
Here we see that for prime modulo we have $1$ and $m - 1$ while for non prime it varies.
Am I right to generalize that for prime it always holds? What is the property that causes this and is there a general conclusion for non prime?

Outline for an answer.
Let $g(m)$ be the number of distinct roots to $x^2\equiv1\pmod m.$
If $m,n$ are relatively prime, then show $g(mn)=g(m)g(n).$ (Hint: use Chinese remainder theorem.) (This property is called being “multiplicative.”)
This is true for any polynomial congruence in one variable. If $h(m)$ is the number of solutions to $x^3+x\equiv 1\pmod m,$ then $h$ is multiplicative.

So we only need to comoute $g(p^k),$ where $p$ is a prime.
If $p$ is an odd prime, then show $g(p^k)=2$ for any $k>0.$
This is because $x^2\equiv 1\pmod {p^k},$ means $p^k\mid x^2-1=(x-1)(x+1).$ But $x-1$ and $x+1$ cannot both be divisible by $p,$ so this means $p^k\mid x-1$ or $p^k\mid +1,$ and thus $x\equiv\pm 1\pmod{p^k}.$
If $p=2,$ you have the problem that $x-1$ and $x+1$ can both be divisible by $2.$
Show that:
$$g(2^k)=\begin{cases}1&k=0,1\\2&k=2\\4&k>2 \end{cases}$$

Finally, if $$m=2^kp_1^{k_1}p_2^{k_2}\cdots p_{n}^{k_n}$$ with the $p_i$ distinct odd primes, then:
$$g(m)=g(2^k)2^n$$
