diff --git a/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.png b/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.png index 58bb0c2..48f1bba 100644 Binary files a/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.png and b/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.png differ diff --git a/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.tex b/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.tex index 0a30208..24c8e4a 100644 --- a/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.tex +++ b/source-code/Pseudocode/Calculate-Legendre/Calculate-Legendre.tex @@ -20,7 +20,7 @@ \ElsIf{$a == 0$ or $a == 1$} \State \Return $a$ \Comment{now: $a \in [2, \dots, p-1]$} \ElsIf{$a == 2$} \Comment{rule (VII)} - \If{$a \equiv \pm 1 \mod 8$} + \If{$p \equiv \pm 1 \mod 8$} \State \Return 1 \Else \State \Return -1 @@ -35,7 +35,7 @@ \State $p_1, p_2, \dots, p_n \gets \Call{Factorize}{a}$ \State \Return $\prod_{i=1}^n \Call{CalculateLegendre}{p_i, p}$ \Else \Comment{now: $a \in \mathbb{P}, \sqrt{p-2} \geq a \geq 3$} - \If{$\frac{p-1}{2} \equiv 0 \mod 2$} + \If{$\frac{p-1}{2} \equiv 0 \mod 2$ or $\frac{a-1}{2} \equiv 0 \mod 2$} \State \Return $\Call{CalculateLegendre}{p, a}$ \Else \State \Return $(-1) \cdot \Call{CalculateLegendre}{p, a}$ diff --git a/source-code/Pseudocode/Calculate-Legendre/calculateLegendre.py b/source-code/Pseudocode/Calculate-Legendre/calculateLegendre.py index 8082880..ea9c340 100644 --- a/source-code/Pseudocode/Calculate-Legendre/calculateLegendre.py +++ b/source-code/Pseudocode/Calculate-Legendre/calculateLegendre.py @@ -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)