Is $n$ always a strong probable prime to base $n - 1$?

82 Views Asked by At

Here is the Miller–Rabin extension to Fermat’s little theorem:

If $p$ is an odd prime and $p - 1 = 2^s d$ with $d$ odd, then for every $a$ coprime to $p$, either $a^d ≡ 1 \pmod p$ or there exists $r$ such that $0 ≤ r < s$ and $a^{2^r d} ≡ -1 \pmod p$.

When turning it into an algorithm, the Miller–Rabin primality test, Cormen et al. in their book Introduction to Algorithms choose $a$ randomly between $1$ and $n - 1$ inclusive.

It is pointless to test for $a = 1$ since it is coprime to $n$ and $a^d = 1^d = 1 ≡ 1 \pmod n$, that is $n$ is always a strong probable prime to base $1$. So we can optimise the algorithm by choosing $a$ randomly between $2$ and $n - 1$ inclusive.

But is it also pointless to test for $a = n - 1$? It is coprime to $n$ but does there always exist $r$ such that $0 ≤ r < s$ and $a^{2^r d} = (n - 1)^{2^r d} ≡ -1 \pmod n$, that is is $n$ always a strong probable prime to base $n - 1$? If that is the case, we can optimise the algorithm by choosing $a$ randomly between $2$ and $n - 2$ inclusive.

1

There are 1 best solutions below

3
On BEST ANSWER

Yes, base $n - 1$ is also pointless because $d$ is odd, so we have

$$(n - 1)^d \equiv (-1)^d = -1 \pmod n.$$

Hence $n$ is always a strong Fermat pseudoprime to base $n - 1$.