Pépin's Test

Theorem
Let $F_n = 2^{2^n} + 1$ be a Fermat number.

Then $F_n$ is prime :
 * $3^{\paren {F_n - 1} / 2} \equiv -1 \pmod {F_n}$

Sufficient Condition
Let this congruence hold:
 * $3^{\paren {F_n - 1} / 2} \equiv -1 \pmod {F_n}$

Then:
 * $3^{F_n - 1} \equiv 1 \pmod {F_n}$

Thus the multiplicative order of $3$ modulo $F_n$ is a divisor of $F_n - 1 = 2^{2^n}$.

This is a power of $2$.

On the other hand, the multiplicative order of $3$ modulo $F_n$ is not a divisor of $\dfrac {F_n - 1} 2$.

Therefore it must be equal to $F_n - 1$.

In particular, there are at least $F_n - 1$ numbers below $F_n$ which are coprime to $F_n<$.

This can happen only if $F_n$ is prime.

Necessary Condition
Let $F_n$ be prime.

By Euler's Criterion:
 * $3^{\paren {F_n - 1} / 2} \equiv \paren {\dfrac 3 {F_n} } \pmod {F_n}$

$\left({\dfrac 3 {F_n} }\right)$ denotes the Legendre symbol.

By repeated squaring:
 * $2^{2^n} \equiv 1 \pmod 3$

Thus:
 * $F_n \equiv 2 \pmod 3$

and so:
 * $\paren {\dfrac {F_n} 3} = -1$

As $F_n \equiv 1 \pmod 4$, it follows from the Law of Quadratic Reciprocity that:
 * $\paren {\dfrac 3 {F_n} } = -1$