Number of elements in a multiplicative group 
Given $n$ the square of a prime odd number. How many elements $\bar x
∈$ $Z^*_n$ with $\bar x ^2$ = $\bar 1$?
Given $n$ the product of two distinct prime numbers. How many elements
  $\bar x ∈$ $Z^*_n$ with $\bar x ^2$ = $\bar 1$?

Not knowing the value of $n$, how can I find out that cardinality? Is there any theorem that I should follow to induce $n$?
 A: For the first question: Let $n = p^2$. We're interested in $x$ such that $x^1 \equiv 1 \pmod {p^2}$. That is $p^2 | x^2 - 1$. We see that this is then equivalent to $p^2 | (x - 1)(x + 1)$. We have three cases: 
$p|(x - 1)$ and $p|(x + 1)$:
If $p|(x - 1)$ and $p|(x + 1)$ then $p|(x + 1 - (x -1 )) = 2$. Since $p$ is an odd prime, this is not possible, so this case cannot happen. 
$p^2|(x - 1)$:
In this case $x \equiv 1 \pmod p^2$. 
$p^2|(x + 1)$:
In this case $x \equiv p^2-1 \pmod p^2$. 
Thus if $n = p^2$ for an odd prime there are exactly two solutions to $x^2 \equiv 1 \pmod n$, namely $1$ and $p^2 - 1$. 
Next suppose $n = pq$ for distinct primes $p$ and $q$. Again we can arrive at the equation $pq|(x + 1)(x - 1)$. We then have four cases: 
$p|(x + 1)$, $q|(x - 1)$: 
In this case we have $x + 1 = kp$ and $x - 1 = mq$. That is $x \equiv 1 \pmod q$ and $x \equiv -1 \pmod p$. Note that by the Chinese Remainder Theorem, this has a unique solution modulo $pq$. 
$p|(x - 1)$, $q|(x + 1)$: 
As above this congruence has a unique solution modulo $pq$ by the Chinese Remainder Theorem. 
$pq|(x + 1)$:
In this case $x \equiv pq - 1 \pmod{pq}$
$pq|(x - 1)$: 
In this case $x \equiv 1 \pmod{pq}$
Next note that one $x$ cannot satisfy any two of the cases above. This is because if such an $x$ did exist then $p|(x + 1)$, $p|(x - 1)$  and $q|(x + 1)$ and $q|(x - 1)$. As in part one, this would for $p = q = 2$, which is a contradiction. Thus there are exactly 4 solutions to $x^2 \equiv 1 \pmod n$ if $n$ is the product of two distinct primes. 
A: $U(p^2)$ is cyclic and so $x^2=1$ has exactly two solutions.
$U(pq) \cong U(p) \times U(q)$ is a product of two cyclic groups and so $x^2=1$ has exactly four solutions.
