When can negative numbers be taken as representatives in modular arithmetic?

100 Views Asked by At

I'm wondering about a step in the Lucas probable prime test:

$V_{2k}=V_k^2-2Q^k$

The Wikipedia article states: At each stage, we reduce $U$, $V$, and the power of $Q$, mod $n$. Depending on whether or not you take the negative number after reducing mod n, the result may be different. For example

Assume $Q$ is negative, such as $-3$. The first U and V are 1. Then $V_2=1-2(-3)^1=1+6=7$ However if you reduce $Q^k$ mod n (where n is positive) one may get the "wrong" answer. For example assume $n=5$ then $-3 \equiv 2(mod5)$ which gives $V_2=1-2(2)=-3$

This might be a non-issue because the test checks if the final term is congruent to 0, which isn't signed. Since it's a sequence the result is used to compute the next term so it's important to know which value to take.

1

There are 1 best solutions below

7
On BEST ANSWER

The ending result will be the correct value modulo $\ n\ $, no matter whether we choose negative or positive residues , as long as they are correct modulo $\ n\ $. So, the signs do not cause a problem.