10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

98 Chapter 2 NUMBER-THEORETICAL TOOLS<br />

and special relations<br />

<br />

−1<br />

=(−1)<br />

m<br />

(m−1)/2 , (2.9)<br />

<br />

2<br />

=(−1)<br />

m<br />

(m2−1)/8 . (2.10)<br />

Furthermore, we have the law of quadratic reciprocity for coprime m, n:<br />

<br />

m n<br />

n m<br />

=(−1) (m−1)(n−1)/4 . (2.11)<br />

Already (2.6) shows that when |a| < p, the Legendre symbol <br />

a<br />

p can be<br />

computed in O ln 3 p bit operations using naive arithmetic and Algorithm<br />

2.1.5; see Exercise 2.17. But we can do better, and we do not even need to<br />

recognize primes.<br />

Algorithm 2.3.5 (Calculation of Legendre/Jacobi symbol). Given positive<br />

odd integer m, and integer a, this algorithm returns the Jacobi symbol <br />

a<br />

m ,which<br />

for m an odd prime is also the Legendre symbol.<br />

1. [Reduction loops]<br />

a = a mod m;<br />

t =1;<br />

while(a = 0) {<br />

while(a even) {<br />

a = a/2;<br />

if(m mod 8 ∈{3, 5}) t = −t;<br />

}<br />

(a, m) =(m, a); // Swap variables.<br />

if(a ≡ m ≡ 3(mod4)) t = −t;<br />

a = a mod m;<br />

}<br />

2. [Termination]<br />

if(m == 1) return t;<br />

return 0;<br />

It is clear that this algorithm does not take materially longer than using<br />

Algorithm 2.1.2 to find gcd(a, m), and so runs in O ln 2 m bit operations<br />

when |a|

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!