Let p be an odd prime. How many quadratic residues are there in Zp?
For an integer a and an odd positive integer n=∏ki=1peii, define the Jacobi symbol:
(an)=k∏i=1(api)ei,where
(ap)={0if a≡0(modp),1if a is a quadratic residue modulo p, and−1if a is a quadratic non-residue modulo pis the Legendre symbol. Prove the following properties for the Jacobi symbol.
If m1≡m2(modn), then (m1n)=(m2n).
Assuming a∈Z∗p:
Using the properties above, and additionally
and
if m and n are odd positive integers, then
(mn)={−(nm)if m≡n≡3(mod4),(nm)otherwise,write an algorithm to evaluate Jacobi symbols. The algorithm should not do any factoring other than dividing out powers of two.
def jacobi(a, n):
v = 1
while True:
a %= n # replace a by its remainder modulo n
if a == 0:
return 0
s = 1 if n % 8 in [1, 7] else -1
while a % 2 == 0:
a //= 2
v *= s
if a == 1:
return v
if a % 4 == 3 and n %% 4 == 3:
v *= -1
a, n = n, a
Calculate (74119283), (209641987) and (123456711111111).