2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

fixed another bug

This commit is contained in:
Martin Thoma 2013-09-01 12:57:42 +02:00
parent b9095ef768
commit 496a8b0adf
3 changed files with 16 additions and 4 deletions

View file

@ -31,13 +31,25 @@ def calculateLegendre(a, p):
-1
>>> calculateLegendre(113, 41) # Beispiel aus dem Skript, S. 114
1
>>> calculateLegendre(2, 31)
1
>>> calculateLegendre(5, 31)
1
>>> calculateLegendre(150, 1009) # http://math.stackexchange.com/q/221223/6876
1
>>> calculateLegendre(25, 1009) # http://math.stackexchange.com/q/221223/6876
1
>>> calculateLegendre(2, 1009) # http://math.stackexchange.com/q/221223/6876
1
>>> calculateLegendre(3, 1009) # http://math.stackexchange.com/q/221223/6876
1
"""
if a >= p or a < 0:
return calculateLegendre(a % p, p)
elif a == 0 or a == 1:
return a
elif a == 2:
if a%8 == 1 or a%8 == 7:
if p%8 == 1 or p%8 == 7:
return 1
else:
return -1
@ -53,7 +65,7 @@ def calculateLegendre(a, p):
product *= calculateLegendre(pi, p)
return product
else:
if ((p-1)/2)%2==0:
if ((p-1)/2)%2==0 or ((a-1)/2)%2==0:
return calculateLegendre(p, a)
else:
return (-1)*calculateLegendre(p, a)