Integer to Power of p-1 over 2 Modulo p

Theorem
Let $a \in \Z$.

Let $p$ be an odd prime.

Let $b = a^{\frac{\left({p - 1}\right)} 2}$.

Then one of the following cases holds:
 * $b \bmod p = 0$

which happens exactly when $a \equiv 0 \pmod p$, or:
 * $b \bmod p = 1$

or:
 * $b \bmod p = p - 1$

where:
 * $b \bmod p$ denotes the modulo operation
 * $x \equiv y \pmod p$ denotes that $x$ is congruent modulo $p$ to $y$.

Proof
By definition of congruence modulo $p$:
 * $\forall x, y \in \R: x \equiv y \pmod p \iff x \bmod p = y \bmod p$

We have that:
 * $b = a^{\frac{\left({p - 1}\right)} 2}$

and so:
 * $b^2 = a^{p - 1}$

Let $a \equiv 0 \pmod p$.

Then by definition of congruence modulo $p$:
 * $p \mathrel \backslash a$

and so:
 * $p \mathrel \backslash a^{\frac{\left({p - 1}\right)} 2}$

where $\backslash$ denotes divisibility.

Thus by definition of congruence modulo $p$:
 * $b \equiv 0 \pmod p$

and so:
 * $b \bmod p = 0$

Otherwise, from Fermat's Little Theorem:
 * $b^2 \equiv 1 \pmod p$

That is:
 * $b^2 - 1 \equiv 0 \pmod p$

From Difference of Two Squares:
 * $b^2 - 1 = \left({b + 1}\right) \left({b - 1}\right)$

So either:
 * $p \mathrel \backslash b + 1$

or:
 * $p \mathrel \backslash b - 1$

both $p \mathrel \backslash b + 1$ and $p \mathrel \backslash b - 1$.

Then by Modulo Subtraction is Well-Defined:
 * $p \mathrel \backslash \left({b + 1}\right) - \left({b - 1}\right) = 2$

But $p$ is an odd prime.

So it cannot be the case that $p \mathrel \backslash 2$.

From this contradiction it follows that

Note that $p$ cannot divide both $b + 1$ and $b - 1$.

So either:
 * $\left({b - 1}\right) \equiv 0 \pmod p$

Hence the result.

Also see

 * Euler's Criterion