Testy pierwszości. Liczby pseudopierwsze Lucasa i liczby silnie pseudopierwsze Lucasa. Test BPSW: Różnice pomiędzy wersjami

Z Henryk Dąbrowski
Przejdź do nawigacji Przejdź do wyszukiwania
 
(Nie pokazano 25 pośrednich wersji utworzonych przez tego samego użytkownika)
Linia 5: Linia 5:
  
  
== Symbol Jacobiego ==
+
== Ciągi Lucasa ==
  
<span style="font-size: 110%; font-weight: bold;">Definicja L1</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Definicja N1</span><br/>
Symbol Jacobiego<ref name="jacobi1"/> <math>\left( {\small\frac{a}{n}} \right)_{\small{\!\! J}}</math> jest uogólnieniem symbolu Legendre'a<ref name="legendre1"/> <math>\left( {\small\frac{a}{p}} \right)_{\small{\!\! L}}</math> dla dodatnich liczb nieparzystych.  
+
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>U_n = U_n (P, Q)</math> i <math>V_n = V_n (P, Q)</math> definiujemy następująco
Niech <math>n = \prod_i p_i^{\alpha_i}</math> będzie rozkładem liczby <math>n</math> na czynniki pierwsze, wtedy
 
  
::<math>\left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} = \prod_i \left( {\small\frac{a}{p_i}} \right)_{\small{\!\! L}}^{\!\! \alpha_i}</math>
+
::<math>U_n = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}}</math>
  
 +
::<math>V_n = \alpha^n + \beta^n</math>
  
 +
gdzie liczby
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L2</span><br/>
+
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}}</math>
Zauważmy, że w&nbsp;przypadku gdy <math>n = 1</math>, po prawej stronie mamy „pusty” iloczyn (bez jakiegokolwiek czynnika). Podobnie jak „pustej” sumie przypisujemy wartość zero, tak „pustemu” iloczynowi przypisujemy wartość jeden. Zatem dla dowolnego <math>a \in \mathbb{Z}</math> jest <math>\left( {\small\frac{a}{1}} \right)_{\small{\!\! J}} = 1</math>.
 
  
 +
::<math>\beta = {\small\frac{P - \sqrt{D}}{2}}</math>
  
 +
są pierwiastkami równania <math>x^2 - P x + Q = 0</math>.
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L3*</span><br/>
 
Niech <math>a, b \in \mathbb{Z}</math> oraz <math>m, n \in \mathbb{Z}_+</math> i <math>m, n</math> będą liczbami nieparzystymi. Symbol Jacobiego ma następujące właściwości
 
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: left; margin-right: auto;"
 
|-
 
| &nbsp;&nbsp;1.&nbsp;&nbsp; || <math>\left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} \,\, = \,\, 0 \quad \Longleftrightarrow \quad \gcd (a, n) > 1</math>
 
|-
 
| &nbsp;&nbsp;2.&nbsp;&nbsp; || <math>a \equiv b \pmod n \quad \Longrightarrow \quad \left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} = \left( {\small\frac{b}{n}} \right)_{\small{\!\! J}}</math>
 
|-
 
| &nbsp;&nbsp;3.&nbsp;&nbsp; || <math>\left( {\small\frac{a b}{n}} \right)_{\small{\!\! J}} \,\, = \,\, \left( {\small\frac{a}{n}} \right)_{\small{\!\! J}} \cdot  \left( {\small\frac{b}{n}} \right)_{\small{\!\! J}}</math>
 
|-
 
| &nbsp;&nbsp;4.&nbsp;&nbsp; || <math>\left( {\small\frac{a}{m n}} \right)_{\small{\!\! J}} \,\, = \,\, \left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} \cdot  \left( {\small\frac{a}{n}} \right)_{\small{\!\! J}}</math>
 
|-
 
| &nbsp;&nbsp;5.&nbsp;&nbsp; || <math>\left( {\small\frac{1}{n}} \right)_{\small{\!\! J}} \,\, = \,\, 1</math>
 
|-
 
| &nbsp;&nbsp;6.&nbsp;&nbsp; || <math>\left( {\small\frac{- 1}{n}} \right)_{\small{\!\! J}} \,\, = \,\, (- 1)^{\tfrac{n - 1}{2}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } n \equiv 1 \pmod{4} \\
 
      - 1 & \text{gdy } n \equiv 3 \pmod{4}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;7.&nbsp;&nbsp; || <math>\left( {\small\frac{2}{n}} \right)_{\small{\!\! J}} \,\, = \,\, (- 1)^{\tfrac{n^2 - 1}{8}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } n \equiv 1, 7 \pmod{8} \\
 
      - 1 & \text{gdy } n \equiv 3, 5 \pmod{8}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;8.&nbsp;&nbsp; || <math>\left( {\small\frac{- 2}{n}} \right)_{\small{\!\! J}} \,\, = \,\, (- 1)^{\tfrac{(n - 1)(n - 3)}{8}} \,\, = \,\,
 
  \begin{cases}
 
\;\;\: 1 & \text{gdy } n \equiv 1, 3 \pmod{8} \\
 
      - 1 & \text{gdy } n \equiv 5, 7 \pmod{8}
 
  \end{cases}</math>
 
|-
 
| &nbsp;&nbsp;9.&nbsp;&nbsp; || <math>\left( {\small\frac{m}{n}} \right)_{\small{\!\! J}} \,\, = \,\, \left( {\small\frac{n}{m}} \right)_{\small{\!\! J}} \cdot (-1)^{\tfrac{n - 1}{2} \cdot \tfrac{m - 1}{2}} \,\, = \,\, \left( {\small\frac{n}{m}} \right)_{\small{\!\! J}} \cdot
 
\begin{cases}
 
\;\;\: 1 & \text{gdy } m \equiv 1 \pmod{4} \;\;\; \text{lub} \;\;\; n \equiv 1 \pmod{4} \\
 
      - 1 & \text{gdy } m \equiv n \equiv 3 \pmod{4}
 
  \end{cases}</math>
 
|}
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga N2</span><br/>
 +
Zauważmy, że:
  
 +
::<math>P = \alpha + \beta</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L4</span><br/>
+
::<math>Q = \alpha \beta</math>
Pokazać, że
 
  
::<math>\left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 12}{m}} \right)_{\small{\!\! J}} =
+
::<math>\sqrt{D} = \alpha - \beta</math>
\begin{cases}
 
\;\;\: 1 & \text{gdy } m = 6 k + 1 \\
 
\;\;\: 0 & \text{gdy } m = 6 k + 3 \\
 
      - 1 & \text{gdy } m = 6 k + 5
 
\end{cases}</math>
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>V_0 = 2</math> i <math>V_1 = P</math>
Zauważmy, że
 
  
::<math>\left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 1}{m}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{3}{m}} \right)_{\small{\!\! J}}</math>
 
  
::::<math>\; = (- 1)^{\tfrac{m - 1}{2}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} \cdot \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
+
Warunek <math>P^2 - 4 Q \neq 0</math> wyklucza następujące pary <math>(P, Q)</math>
  
::::<math>\; = (- 1)^{m - 1} \cdot \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
+
::<math>(0, 0), (\pm 2, 1), (\pm 4, 4), (\pm 6, 9), (\pm 8, 16), (\pm 10, 25), (\pm 12, 36), ..., (\pm 2 n, n^2), ...</math>
  
::::<math>\; = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
 
  
bo <math>m</math> jest liczbą nieparzystą.
 
  
Rozważmy liczby nieparzyste <math>m</math> postaci <math>6 k + r</math>, gdzie <math>r = 1, 3, 5</math>. Mamy
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N3</span><br/>
 +
Oczywiście liczby <math>\alpha</math> i <math>\beta</math> są również pierwiastkami równania
  
::<math>\left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}}</math>
+
::<math>x^{n + 2} - P x^{n + 1} + Q x^n = 0</math>
  
::::<math>\; = \left( {\small\frac{6 k + r}{3}} \right)_{\small{\!\! J}}</math>
+
Wynika stąd, że ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math> spełniają równania rekurencyjne
  
::::<math>\; = \left( {\small\frac{r}{3}} \right)_{\small{\!\! J}}</math>
+
::<math>\alpha^{n + 2} = P \alpha^{n + 1} - Q \alpha^n</math>
  
::::<math>\; =
+
::<math>\beta^{n + 2} = P \beta^{n + 1} - Q \beta^n</math>
\begin{cases}
 
\;\;\: 1 & \text{gdy } r = 1 \\
 
\;\;\: 0 & \text{gdy } r = 3 \\
 
      - 1 & \text{gdy } r = 5
 
\end{cases}</math>
 
  
bo odpowiednio dla <math>r = 1, 3, 5</math> jest
+
Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> spełniają identyczne równania rekurencyjne jak ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math>. Istotnie, odejmując i&nbsp;dodając stronami wypisane powyżej równania, otrzymujemy
  
::<math>\left( {\small\frac{1}{3}} \right)_{\small{\!\! J}} = 1</math>
+
::<math>U_{n + 2} = P U_{n + 1} - Q U_n</math>
  
::<math>\left( {\small\frac{3}{3}} \right)_{\small{\!\! J}} = 0</math>
+
::<math>V_{n + 2} = P V_{n + 1} - Q V_n</math>
  
::<math>\left( {\small\frac{5}{3}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{3}} \right)_{\small{\!\! J}} = (- 1)^{\tfrac{9 - 1}{8}} = - 1</math>
+
Dlatego możemy zdefiniować ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> w&nbsp;sposób równoważny
  
Łatwo zauważamy, że
 
  
::<math>\left( {\small\frac{- 12}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 3 \cdot 2^2}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{2}{m}} \right)_{\small{\!\! J}}^{\! 2} = \left( {\small\frac{- 3}{m}} \right)_{\small{\!\! J}}</math>
 
  
Co należało pokazać.<br/>
+
<span style="font-size: 110%; font-weight: bold;">Definicja N4</span><br/>
&#9633;
+
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> określone są następującymi wzorami rekurencyjnymi
{{\Spoiler}}
 
  
 +
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>U_n = P U_{n - 1} - Q U_{n - 2}</math>
  
 +
::<math>V_0 = 2</math>, <math>V_1 = P</math>, <math>V_n = P V_{n - 1} - Q V_{n - 2}</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L5</span><br/>
 
Pokazać, że
 
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} =
 
\begin{cases}
 
\;\;\: 1 & \text{gdy } m = 12 k \pm 1 \\
 
\;\;\: 0 & \text{gdy } m = 12 k \pm 3 \\
 
      - 1 & \text{gdy } m = 12 k \pm 5
 
\end{cases}</math>
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Przykład N5</span><br/>
 +
Początkowe wyrazy ciągów Lucasa
  
::<math>\left( {\small\frac{- 4}{m}} \right)_{\small{\!\! J}} =
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: left; margin-right: auto;"
\begin{cases}
+
|-
\;\;\: 1 & \text{gdy } m = 4 k + 1 \\
+
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{U_n (P, Q)}</math> !! <math>\boldsymbol{V_n (P, Q)}</math>
      - 1 & \text{gdy } m = 4 k + 3
+
|-
\end{cases}</math>
+
| &nbsp;&nbsp;<math>0</math>&nbsp;&nbsp; || <math>0</math> || <math>2</math>
 +
|-
 +
| &nbsp;&nbsp;<math>1</math>&nbsp;&nbsp; || <math>1</math> || <math>P</math>
 +
|-
 +
| &nbsp;&nbsp;<math>2</math>&nbsp;&nbsp; || <math>P</math> || <math>P^2 - 2 Q</math>
 +
|-
 +
| &nbsp;&nbsp;<math>3</math>&nbsp;&nbsp; || <math>P^2 - Q</math> || <math>P^3 - 3 P Q</math>
 +
|-
 +
| &nbsp;&nbsp;<math>4</math>&nbsp;&nbsp; || <math>P^3 - 2 P Q</math> || <math>P^4 - 4 P^2 Q + 2 Q^2</math>
 +
|-
 +
| &nbsp;&nbsp;<math>5</math>&nbsp;&nbsp; || <math>P^4 - 3 P^2 Q + Q^2</math> || <math>P^5 - 5 P^3 Q + 5 P Q^2</math>
 +
|-
 +
| &nbsp;&nbsp;<math>6</math>&nbsp;&nbsp; || <math>P^5 - 4 P^3 Q + 3 P Q^2</math> || <math>P^6 - 6 P^4 Q + 9 P^2 Q^2 - 2 Q^3</math>
 +
|-
 +
| &nbsp;&nbsp;<math>7</math>&nbsp;&nbsp; || <math>P^6 - 5 P^4 Q + 6 P^2 Q^2 - Q^3</math> || <math>P^7 - 7 P^5 Q + 14 P^3 Q^2 - 7 P Q^3</math>
 +
|-
 +
| &nbsp;&nbsp;<math>8</math>&nbsp;&nbsp; || <math>P^7 - 6 P^5 Q + 10 P^3 Q^2 - 4 P Q^3</math> || <math>P^8 - 8 P^6 Q + 20 P^4 Q^2 - 16 P^2 Q^3 + 2 Q^4</math>
 +
|-
 +
| &nbsp;&nbsp;<math>9</math>&nbsp;&nbsp; || <math>P^8 - 7 P^6 Q + 15 P^4 Q^2 - 10 P^2 Q^3 + Q^4</math> || <math>P^9 - 9 P^7 Q + 27 P^5 Q^2 - 30 P^3 Q^3 + 9 P Q^4</math>
 +
|}
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 1}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k}{2}} = \left( {\small\frac{1}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{6 k} = 1</math>
 
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 5}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k + 4}{2}} = \left( {\small\frac{5}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{(6 k + 2)} = \left( {\small\frac{2}{3}} \right)_{\small{\!\! J}} = - 1</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N6</span><br/>
 +
W PARI/GP możemy napisać prosty kod, który pozwoli obliczyć wartości wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 7}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k + 6}{2}} = \left( {\small\frac{1}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{(6 k + 3)} = - 1</math>
+
<span style="font-size: 90%; color:black;">LucasU(n, P, Q) = '''if'''( n == 0, 0, '''if'''( n == 1, 1, P*LucasU(n-1, P, Q) - Q*LucasU(n-2, P, Q) ) )</span>
  
::<math>\left( {\small\frac{3}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{m}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{m - 1}{2} \cdot \tfrac{3 - 1}{2}} = \left( {\small\frac{12 k + 11}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{12 k + 10}{2}} = \left( {\small\frac{2}{3}} \right)_{\small{\!\! J}} \cdot (- 1)^{(6 k + 5)} = (- 1) \cdot (- 1) = 1</math>
+
<span style="font-size: 90%; color:black;">LucasV(n, P, Q) = '''if'''( n == 0, 2, '''if'''( n == 1, P, P*LucasV(n-1, P, Q) - Q*LucasV(n-2, P, Q) ) )</span>
<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
  
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L6</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N7</span><br/>
Wykorzystując podane wyżej właściwości symbolu Jacobiego, możemy napisać prostą funkcję w&nbsp;PARI/GP znajdującą jego wartość. Zauważmy, że nie potrzebujemy znać rozkładu liczby <math>n</math> na czynniki pierwsze.
+
Niech <math>D = P^2 - 4 Q</math>. Wyrazy ciągów Lucasa można przedstawić w&nbsp;postaci sumy
  
<span style="font-size: 90%; color:black;">jacobi(a, n) =  
+
::<math>2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
{
 
'''local'''(r, w);
 
'''if'''( n <= 0 || n % 2 == 0, '''return'''("Error") );
 
a = a % n; \\ korzystamy ze wzoru (a|n) = (b|n), gdy a &equiv; b (mod n)
 
w = 1;
 
'''while'''( a <> 0,
 
        '''while'''( a % 2 == 0, a = a/2; r = n % 8; '''if'''( r == 3 || r == 5, w = -w ) );
 
        \\ usunęliśmy czynnik 2 ze zmiennej a, uwzględniając, że (2|n) = -1, gdy n &equiv; 3,5 (mod 8)
 
        \\ teraz zmienne a oraz n są nieparzyste
 
        r = a; \\ zmienna r tylko przechowuje wartość a
 
        a = n;
 
        n = r;
 
        '''if'''( a % 4 == 3 && n % 4 == 3, w = -w );
 
        \\ zamieniliśmy zmienne, uwzględniając, że (a|n) = - (n|a), gdy a &equiv; n &equiv; 3 (mod 4)
 
        a = a % n;
 
      );
 
'''if'''( n == 1, '''return'''(w), '''return'''(0) ); \\ n jest teraz równe gcd(a, n)
 
}</span>
 
  
 +
::<math>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L7</span><br/>
+
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
Ten rozdział moglibyśmy zakończyć na podaniu kodu funkcji <code>jacobi(a, m)</code>. Dlatego Czytelnik może pominąć dalsze rozważania i&nbsp;wrócić do nich, gdy będziemy omawiali metodę Selfridge'a – dopiero tam pojęcie najmniejszej liczby niekwadratowej modulo <math>p</math> nabierze znaczenia, a&nbsp;i&nbsp;tak nie będzie konieczne dla zrozumienia tematu.
 
  
 +
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
  
 +
Obliczając sumę powyższych wzorów, otrzymujemy
  
<span style="font-size: 110%; font-weight: bold;">Przykład L8</span><br/>
+
::<math>2^n (\alpha^n + \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j + (- \delta)^j)</math>
W tabeli przedstawiliśmy najmniejsze liczby <math>g = g (m)</math> takie, że <math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = - 1</math>.
 
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
+
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} \cdot 2 \delta^{2 k}</math>
! <math>\boldsymbol{m}</math>
 
| <math>3</math> || <math>5</math> || <math>7</math> || <math>9</math> || <math>11</math> || <math>13</math> || <math>15</math> || <math>17</math> || <math>19</math> || <math>21</math> || <math>23</math> || <math>25</math> || <math>27</math> || <math>29</math> || <math>31</math> || <math>33</math> || <math>35</math> || <math>37</math> || <math>39</math> || <math>41</math> || <math>43</math> || <math>45</math> || <math>47</math> || <math>49</math> || <math>51</math>
 
|-
 
!  <math>\boldsymbol{g}</math>
 
| <math>2</math> || <math>2</math> || <math>3</math> || <math>-</math> || <math>2</math> || <math>2</math> || <math>7</math> || <math>3</math> || <math>2</math> || <math>2</math> || <math>5</math> || <math>-</math> || <math>2</math> || <math>2</math> || <math>3</math> || <math>5</math> || <math>2</math> || <math>2</math> || <math>7</math> || <math>3</math> || <math>2</math> || <math>2</math> || <math>5</math> || <math>-</math> || <math>2</math>
 
|}
 
  
 +
:::::<math>\quad \: = 2 \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
  
Do wyszukiwania liczb <math>g = g (m)</math> (nazywanych najmniejszymi liczbami niekwadratowymi modulo <math>m</math>) Czytelnik może wykorzystać prostą funkcję napisaną w&nbsp;PARI/GP
+
gdzie <math>j = 2 k</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor n / 2 \rfloor</math>
  
<span style="font-size: 90%; color:black;">LeastQuadraticNonresidue(m) =
+
Zatem
{
 
'''local'''(g);
 
'''if'''( m%2 == 0, '''return'''(0) );
 
'''if'''( '''issquare'''(m), '''return'''(0) );
 
'''forprime'''(g = 2, m, '''if'''( jacobi(g, m) == -1, '''return'''(g) ));
 
}</span>
 
  
 +
::<math>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
  
O&nbsp;liczbach kwadratowych i&nbsp;niekwadratowych modulo podamy jedynie podstawowe fakty.
 
  
Niech liczby <math>a</math> i <math>m \geqslant 1</math> będą względnie pierwsze.
+
Obliczając różnicę tych wzorów, mamy
  
:* jeżeli istnieje taka liczba <math>r</math>, że <math>r^2 \equiv a \pmod{m}</math>, to <math>a</math> jest liczbą kwadratową modulo <math>m</math>.
+
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j)</math>
:* jeżeli nie istnieje taka liczba <math>r</math>, że <math>r^2 \equiv a \pmod{m}</math>, to <math>a</math> jest liczbą niekwadratową modulo <math>m</math>.
 
  
 +
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} \cdot 2 \delta^{2 k + 1}</math>
  
Zauważmy również, że (w przypadku, gdy <math>m</math> jest liczbą nieparzystą)
+
:::::<math>\quad \: = 2 \delta \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
  
:* jeżeli <math>\left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} = - 1</math>, to <math>a</math> jest liczbą niekwadratową modulo <math>m</math>
+
gdzie <math>j = 2 k + 1</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor (n - 1) / 2 \rfloor</math>
:* jeżeli <math>\left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} = + 1</math>, to <math>a</math> nie musi być liczbą kwadratową modulo <math>m</math>
 
:* jeżeli <math>a</math> jest liczbą kwadratową modulo <math>m</math>, to <math>\left( {\small\frac{a}{m}} \right)_{\small{\!\! J}} = + 1</math>
 
  
Dla przykładu: jeżeli <math>\gcd (a, m) = 1</math>, to <math>\left( {\small\frac{a}{m^2}} \right)_{\small{\!\! J}} = + 1</math>, ale <math>a</math> może być liczbą niekwadratową modulo <math>m^2</math>.
 
  
Modulo <math>9</math> liczbami niekwadratowymi są: <math>2, 5, 8</math>. Modulo <math>25</math> liczbami niekwadratowymi są: <math>2, 3, 7, 8, 12, 13, 17, 18, 22, 23</math>.
+
Zatem
  
Liczby kwadratowe i&nbsp;niekwadratowe modulo <math>m</math> można łatwo znaleźć, wykorzystując prosty program:
+
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} = 2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
 +
 
 +
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
<span style="font-size: 90%; color:black;">QRandQNR(m) =
 
{
 
'''local'''(k, S, V);
 
S = [];
 
V = [];
 
'''for'''(k = 1,  m - 1, '''if'''( '''gcd'''(k, m) > 1, '''next'''() ); S = '''concat'''(S, k));
 
S = '''Set'''(S); \\ zbiór liczb względnie pierwszych z m
 
'''for'''(k = 1,  m - 1, '''if'''( '''gcd'''(k, m) > 1, '''next'''() ); V = '''concat'''(V, k^2 % m));
 
V = '''Set'''(V); \\ zbiór liczb kwadratowych modulo m
 
'''print'''("QR: ", V);
 
'''print'''("QNR: ", '''setminus'''(S, V)); \\ różnica zbiorów S i V
 
}</span>
 
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga N8</span><br/>
 +
Korzystając z&nbsp;twierdzenia N7, możemy napisać proste funkcje do znajdowania postaci kolejnych wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L9</span><br/>
+
<span style="font-size: 90%; color:black;">U(n) = 2^(1 - n)*'''sum'''(k=0, '''floor'''((n-1)/2), '''binomial'''(n, 2*k+1) * P^(n-2*k-1) * (P^2-4*Q)^k)</span>
Niech <math>g, m \in \mathbb{Z}_+</math> i&nbsp;niech <math>m \geqslant 3</math> będzie liczbą nieparzystą, a <math>g</math> będzie najmniejszą liczbą taką, że <math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = - 1</math>. Liczba <math>g</math> musi być liczbą pierwszą.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
<span style="font-size: 90%; color:black;">V(n) = 2^(1 - n)*'''sum'''(k=0, '''floor'''(n/2), '''binomial'''(n, 2*k) * P^(n-2*k) * (P^2-4*Q)^k)</span>
Przypuśćmy, że <math>g = a b</math> jest liczbą złożoną, gdzie <math>1 < a, b < g</math>. Mamy
 
  
::<math>- 1 = \left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{a b}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{a}{m}} \right)_{\small{\!\! J}}</math><math>\left( {\small\frac{b}{m}} \right)_{\small{\!\! J}}</math>
 
  
Zatem jeden z&nbsp;czynników po prawej stronie musi być równy <math>- 1</math> wbrew definicji liczby <math>g</math>.<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
 +
Często możemy spotkać założenie <math>P \geqslant 1</math>. Poniższe twierdzenie wyjaśnia, dlaczego tak jest.
  
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N9</span><br/>
 +
Jeżeli <math>(U_n)</math> i <math>(V_n)</math> są ciągami Lucasa, to
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L10</span><br/>
+
::<math>U_n (- P, Q) = (- 1)^{n - 1} U_n (P, Q)</math>
Niech <math>p</math> będzie liczbą pierwszą nieparzystą, a <math>g</math> będzie najmniejszą liczbą pierwszą taką, że <math>\left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - 1</math>. Prawdziwe jest oszacowanie
 
  
::<math>g (p) < \sqrt{p} + {\small\frac{1}{2}}</math>
+
::<math>V_n (- P, Q) = (- 1)^n V_n (P, Q)</math>
  
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
Niech <math>u = g - R_g (p)</math>, gdzie <math>R_g (p)</math> jest resztą z&nbsp;dzielenia liczby <math>p</math> przez <math>g</math>. Ponieważ <math>g \nmid p</math>, zatem <math>R_g (p) \neq 0</math> i <math>u \in [1, g - 1]</math>. Mamy
+
Niech
  
::<math>u = g - R_g (p) \equiv g + p - R_g (p) = {\small\frac{g + p - R_g (p)}{g}} \cdot g = b g \pmod{p}</math>
+
::<math>\alpha = \frac{P + \sqrt{D}}{2} \qquad \qquad \;\; \beta = \frac{P - \sqrt{D}}{2}</math>
  
gdzie oznaczyliśmy
+
::<math>a = \frac{- P + \sqrt{D}}{2} \qquad \qquad b = \frac{- P - \sqrt{D}}{2}</math>
  
::<math>b = {\small\frac{g + p - R_g (p)}{g}}</math>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
  
Ponieważ z&nbsp;założenia <math>p</math> jest liczbą pierwszą, to <math>\gcd (u, p) = 1</math> i&nbsp;musi być <math>\left( {\small\frac{u}{p}} \right)_{\small{\!\! J}} = 1</math>, bo <math>u < g</math>. Zatem
+
::<math>x^2 - P x + Q = 0</math>
  
::<math>1 = \left( {\small\frac{u}{p}} \right)_{\small{\!\! J}} = \left( {\small\frac{b g}{p}} \right)_{\small{\!\! J}} = \left( {\small\frac{b}{p}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - \left( {\small\frac{b}{p}} \right)_{\small{\!\! J}}</math>
+
::<math>x^2 + P x + Q = 0</math>
  
Ale z&nbsp;założenia <math>g</math> jest najmniejszą liczbą taką, że <math>\left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - 1</math>. Wynika stąd, że musi być <math>g \leqslant b</math> i&nbsp;łatwo znajdujemy, że
+
Zatem definiują one ciągi Lucasa
  
::<math>g \leqslant {\small\frac{g + p - R_g (p)}{g}} \leqslant {\small\frac{g + p - 1}{g}}</math>
+
::<math>U_n (P, Q) = \frac{\alpha^n - \beta^n}{\alpha - \beta} \qquad \qquad \;\; V_n (P, Q) = \alpha^n + \beta^n</math>
  
Czyli
+
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} \qquad \qquad V_n (- P, Q) = a^n + b^n</math>
  
::<math>g^2 \leqslant g + p - 1</math>
+
Zauważmy, że
  
Skąd otrzymujemy
+
::<math>\alpha - \beta = a - b = \sqrt{D}</math>
  
::<math>\left( g - {\small\frac{1}{2}} \right)^2 \leqslant p - {\small\frac{3}{4}}</math>
+
::<math>\frac{a}{\beta} = \frac{b}{\alpha} = - 1</math>
  
::<math>g \leqslant {\small\frac{1}{2}} + \sqrt{p - {\small\frac{3}{4}}} < {\small\frac{1}{2}} + \sqrt{p}</math>
+
Łatwo znajdujemy
 +
 
 +
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} = \frac{(- \beta)^n - (- \alpha)^n}{\sqrt{D}} = (- 1)^n \cdot \frac{\beta^n - \alpha^n}{\alpha - \beta} = (- 1)^{n - 1} \cdot U_n (P, Q)</math>
 +
 
 +
::<math>V_n (- P, Q) = a^n + b^n = (- \beta)^n + (- \alpha)^n = (- 1)^n \cdot (\alpha^n + \beta^n) = (- 1)^n \cdot V_n (P, Q)</math>
  
 
Co należało pokazać.<br/>
 
Co należało pokazać.<br/>
Linia 290: Linia 216:
  
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L11*</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Zadanie N10</span><br/>
Niech <math>p</math> będzie liczbą pierwszą nieparzystą, a <math>g</math> będzie najmniejszą liczbą pierwszą taką, że <math>\left( {\small\frac{g}{p}} \right)_{\small{\!\! J}} = - 1</math>. Dla <math>p \geqslant 5</math> prawdziwe jest oszacowanie<ref name="Norton1"/><ref name="Trevino1"/><ref name="Trevino2"/>
+
Pokazać, że jeżeli <math>P, Q \in \mathbb{Z} \setminus \{ 0 \}</math> i <math>D = P^2 - 4 Q \neq 0</math>, to
  
::<math>g (p) \leqslant 1.1 \cdot p^{1 / 4} \log p</math>
+
::<math>U_n (2 P, 4 Q) = 2^{n - 1} U_n (P, Q)</math>
  
 +
::<math>V_n (2 P, 4 Q) = 2^n V_n (P, Q)</math>
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Niech
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L12</span><br/>
+
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}} \qquad \qquad \;\; \beta = {\small\frac{P - \sqrt{D}}{2}}</math>
W przypadku liczb złożonych podane w&nbsp;twierdzeniu L10 oszacowanie <math>g(m) < \sqrt{m} + {\small\frac{1}{2}}</math> nie jest prawdziwe. Mamy
 
  
::<math>g = g (15) = 7 > \sqrt{15} + {\small\frac{1}{2}} \approx 4.37</math>
+
::<math>a = P + \sqrt{D} \qquad \qquad \;\; b = P - \sqrt{D}</math>
  
::<math>g = g (39) = 7 > \sqrt{39} + {\small\frac{1}{2}} \approx 6.74</math>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
  
::<math>g = g (105) = 11 > \sqrt{105} + {\small\frac{1}{2}} \approx 10.75</math>
+
::<math>x^2 - P x + Q = 0</math>
  
::<math>g = g (231) = 17 > \sqrt{231} + {\small\frac{1}{2}} \approx 15.7</math>
+
::<math>x^2 - 2 P x + 4 Q = 0</math>
  
Nie ma więcej takich przypadków dla <math>m < 10^9</math>.
+
Zatem definiują one ciągi Lucasa
  
 +
::<math>U_n (P, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \;\;\; V_n (P, Q) = \alpha^n + \beta^n</math>
  
 +
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (2 P, 4 Q) = a^n + b^n</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L13</span><br/>
+
Zauważmy, że
Niech <math>p</math> będzie liczbą pierwszą nieparzystą, a&nbsp;liczby <math>u_k = a k + b</math> tworzą ciąg arytmetyczny oraz <math>\gcd (a, p) = 1</math>. Ciąg <math>(u_k)</math> zawiera nieskończenie wiele liczb kwadratowych i&nbsp;nieskończenie wiele liczb niekwadratowych modulo <math>p</math>.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
::<math>\alpha - \beta = \sqrt{D}</math>
Wystarczy pokazać, że w&nbsp;ciągu <math>u_k = a k + b</math> rozpatrywanym modulo <math>p</math> występuje każda z&nbsp;liczb <math>0, 1, 2, \ldots, p - 1</math>. Niech <math>r</math> oznacza dowolną z&nbsp;tych liczb. Musimy pokazać istnienie takiej liczby <math>k</math>, że
 
  
::<math>u_k = a k + b \equiv r \pmod{p}</math>
+
::<math>a - b = 2 \sqrt{D}</math>
  
::<math>a k \equiv r - b \pmod{p}</math>
+
::<math>{\small\frac{a}{\alpha}} = {\small\frac{b}{\beta}} = 2</math>
  
Ponieważ <math>\gcd (a, p) = 1</math>, to istnieją takie liczby <math>x, y</math>, że <math>a x + p y = 1</math> (zobacz C69 – lemat Bézouta). Zauważmy, że <math>p \nmid x</math>, bo gdyby tak było, to liczba <math>p</math> dzieliłaby wyrażenie <math>a x + p y</math>, ale jest to niemożliwe, bo <math>a x + p y = 1</math>. Zatem
+
Łatwo znajdujemy
  
::<math>a x k \equiv x (r - b) \pmod{p}</math>
+
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} = {\small\frac{(2 \alpha)^n - (2 \beta)^n}{2 \sqrt{D}}} = 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = 2^{n - 1} U_n (P, Q)</math>
  
::<math>(1 - p y) k \equiv x (r - b) \pmod{p}</math>
+
::<math>V_n (2 P, 4 Q) = a^n + b^n = (2 \alpha)^n + (2 \beta)^n = 2^n (\alpha^n + \beta^n) = 2^n V_n (P, Q)</math>
  
::<math>k - p y k \equiv x (r - b) \pmod{p}</math>
+
Co należało pokazać.<br/>
 
 
::<math>k \equiv x (r - b) \pmod{p}</math>
 
 
 
Czyli szukana liczba <math>k</math> istnieje dla każdego <math>r \in [0, 1, \ldots, p - 1]</math>. Co kończy dowód.<br/>
 
 
&#9633;
 
&#9633;
 
{{\Spoiler}}
 
{{\Spoiler}}
Linia 338: Linia 262:
  
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L14</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Zadanie N11</span><br/>
Metody użytej w&nbsp;dowodzie twierdzenia L10 nie można stosować w przypadku liczb złożonych, bo łatwo można znaleźć przykłady takich złożonych liczb <math>m</math>, że każda z&nbsp;liczb <math>u \in [1, g - 1]</math> (poza liczbą <math>1</math> i&nbsp;potęgami liczby <math>2</math>) nie jest względnie pierwsza z <math>m</math>. Niech <math>g = p_{n + 1}</math>, gdzie <math>n \geqslant 2</math>, oraz <math>r = p_2 \cdot \ldots \cdot p_n</math> będzie iloczynem wszystkich liczb pierwszych nieparzystych mniejszych od <math>g</math>. Z&nbsp;definicji liczby <math>r</math> wynika, że
+
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q - 1</math>, to
  
* dla każdej liczby pierwszej nieparzystej <math>q</math> mniejszej od <math>g</math> mamy <math>\left( {\small\frac{q}{r}} \right)_{\small{\!\! J}} = 0</math>
+
::<math>U_{2 k} (P, P Q) = - (- P)^k U_{2 k} (1, Q)</math>
  
* każda z&nbsp;liczb <math>u \in [1, g - 1]</math> (poza liczbą <math>1</math> i&nbsp;potęgami liczby <math>2</math>) nie jest względnie pierwsza z <math>r</math>
+
::<math>U_{2 k + 1} (P, P Q) = (- P)^k V_{2 k + 1} (1, Q)</math>
  
 +
::<math>V_{2 k} (P, P Q) = (- P)^k V_{2 k} (1, Q)</math>
  
Zauważmy, że
+
::<math>V_{2 k + 1} (P, P Q) = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
  
* jeżeli <math>\left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = + 1</math> i <math>\left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = - 1</math>, to <math>r</math> jest poszukiwaną liczbą, czyli <math>m = r</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Niech
  
* jeżeli <math>\left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = - 1</math>, to wystarczy znaleźć liczbę nieparzystą <math>k</math> taką, że <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = + 1</math>, wtedy liczba <math>m = k r</math> jest poszukiwaną liczbą, bo
+
::<math>\alpha = {\small\frac{1 + \sqrt{- P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{- P}}{2}}</math>
  
::<math>\left( {\small\frac{2}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = (- 1) \cdot (- 1) = + 1</math>
+
::<math>a = {\small\frac{P + \sqrt{- P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{- P}}{2}}</math>
  
::<math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = (+ 1) \cdot (- 1) = - 1</math>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
  
* jeżeli <math>\left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = + 1</math>, to wystarczy znaleźć liczbę nieparzystą <math>k</math> taką, że <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}}</math>, wtedy liczba <math>m = k r</math> jest poszukiwaną liczbą, bo
+
::<math>x^2 - x + {\small\frac{P + 1}{4}} = 0</math>
  
::<math>\left( {\small\frac{2}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}} = \left( {\small\frac{2}{r}} \right)_{\small{\!\! J}}^{\! 2} = + 1</math>
+
::<math>x^2 - P x + {\small\frac{P (P + 1)}{4}} = 0</math>
  
::<math>\left( {\small\frac{g}{m}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k r}} \right)_{\small{\!\! J}} = \left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} \cdot \left( {\small\frac{g}{r}} \right)_{\small{\!\! J}} = (- 1) \cdot (+ 1) = - 1</math>
+
Z założenia <math>P = 4 Q - 1</math>, zatem
  
 +
::<math>x^2 - x + Q = 0</math>
  
Zauważmy, że poszukiwana liczba <math>k</math> istnieje. Pokażemy to dla punktu drugiego, ale Czytelnik bez trudu może powtórzyć poniższe rozważania dla punktu trzeciego. Szukamy liczby <math>k</math> takiej, że <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = - 1</math> i <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = + 1</math>. Ponieważ musi być <math>\left( {\small\frac{2}{k}} \right)_{\small{\!\! J}} = - 1</math>, to <math>k</math> musi być postaci <math>k = 8 j \pm 3</math>. Niech <math>k = 8 j - 3</math>, mamy
+
::<math>x^2 - P x + P Q = 0</math>
  
::<math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = \left( {\small\frac{k}{g}} \right)_{\small{\!\! J}} \cdot (- 1)^{\tfrac{k - 1}{2} \cdot \tfrac{g - 1}{2}}</math>
+
Czyli definiują one ciągi Lucasa
  
Wykładnik jest liczbą parzystą, bo <math>{\small\frac{g - 1}{2}}</math> jest liczbą całkowitą, a <math>{\small\frac{k - 1}{2}} = 4 j - 2</math>. Zatem
+
::<math>U_n (1, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \:\:\: V_n (1, Q) = \alpha^n + \beta^n</math>
  
::<math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = \left( {\small\frac{k}{g}} \right)_{\small{\!\! J}} = \left( {\small\frac{8 j - 3}{g}} \right)_{\small{\!\! J}}</math>
+
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
  
Ponieważ <math>\gcd (8, g) = 1</math>, to ciąg arytmetyczny liczb <math>k = 8 j - 3</math> zawiera nieskończenie wiele liczb kwadratowych i&nbsp;nieskończenie wiele liczb niekwadratowych modulo <math>g</math> (zobacz L13), zatem istnieje taki wyraz <math>k = 8 j - 3</math>, że <math>\left( {\small\frac{g}{k}} \right)_{\small{\!\! J}} = + 1</math>.
+
Zauważmy, że
  
 +
::<math>\alpha - \beta = a - b = \sqrt{- P}</math>
  
Poniżej podajemy przykłady najmniejszych liczb <math>k</math> dla kolejnych liczb <math>g</math>. Nie wypisujemy pełnych iloczynów <math>m = k r</math>, bo są to zbyt duże liczby. Przykładowo liczba <math>m = k r</math> dla <math>g = 97</math> jest równa <math>m \approx 3.565 \cdot 10^{34}</math>.
+
::<math>{\small\frac{a}{\beta}} = {\small\frac{P + \sqrt{- P}}{1 - \sqrt{- P}}} = \sqrt{- P}</math>
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
+
::<math>{\small\frac{b}{\alpha}} = {\small\frac{P - \sqrt{- P}}{1 + \sqrt{- P}}} = - \sqrt{- P}</math>
! <math>g</math>
 
| <math>5</math> || <math>7</math> || <math>11</math> || <math>13</math> || <math>17</math> || <math>19</math> || <math>23</math> || <math>29</math> || <math>31</math> || <math>37</math> || <math>41</math> || <math>43</math> || <math>47</math> || <math>53</math> || <math>59</math> || <math>61</math> || <math>67</math> || <math>71</math> || <math>73</math> || <math>79</math> || <math>83</math> || <math>89</math> || <math>97</math>
 
|-
 
! <math>k</math>
 
| <math>11</math> || <math>1</math> || <math>1</math> || <math>3</math> || <math>7</math> || <math>1</math> || <math>11</math> || <math>3</math> || <math>1</math> || <math>1</math> || <math>5</math> || <math>5</math> || <math>7</math> || <math>23</math> || <math>5</math> || <math>7</math> || <math>3</math> || <math>15</math> || <math>1</math> || <math>1</math> || <math>7</math> || <math>5</math> || <math>3</math>
 
|}
 
  
  
 +
Łatwo znajdujemy
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L15</span><br/>
+
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k} - \left( - \alpha \sqrt{- P} \right)^{2 k}}{\sqrt{- P}} = \frac{(- P)^k (\beta^{2 k} - \alpha^{2 k})}{\alpha - \beta} = - (- P)^k U_{2 k} (1, Q)</math>
Liczby <math>g = g (m)</math> są zaskakująco małe. Średnia wartość <math>g = g (p)</math>, gdzie <math>p</math> są nieparzystymi liczbami pierwszymi, jest równa<ref name="Erdos1"/>
 
  
::<math>\lim_{x \to \infty} {\small\frac{1}{\pi (x)}} \sum_{p \leqslant x} g (p) = \sum_{k = 1}^{\infty} {\small\frac{p_k}{2^k}} = 3.674643966 \ldots</math>
 
  
A średnia wartość <math>g = g (m)</math>, gdzie <math>m</math> są liczbami nieparzystymi (przyjmujemy <math>g(m) = 0</math>, gdy <math>m</math> jest liczbą kwadratową) wynosi<ref name="BaillieWagstaff1"/>
+
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k + 1} - \left( - \alpha \sqrt{- P} \right)^{2 k + 1}}{\sqrt{- P}} = (- P)^k (\beta^{2 k + 1} + \alpha^{2 k + 1}) = (- P)^k V_{2 k + 1} (1, Q)</math>
  
::<math>\lim_{x \to \infty} {\small\frac{1}{x / 2}} \underset{m \; \text{nieparzyste}}{\sum_{m \leqslant x}} g (m) = \sum_{k = 2}^{\infty} {\small\frac{p_k + 1}{2^{k - 1}}} \prod^{k - 1}_{j = 1} \left( 1 - {\small\frac{1}{p_j}} \right) = 3.147755149 \ldots</math>
 
  
 +
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \beta \sqrt{- P} \right)^{2 k} + \left( - \alpha \sqrt{- P} \right)^{2 k} = (- P)^k (\alpha^{2 k} + \beta^{2 k}) = (- P)^k V_{2 k} (1, Q)</math>
  
  
 +
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \beta \sqrt{- P} \right)^{2 k + 1} + \left( - \alpha \sqrt{- P} \right)^{2 k + 1} = (- P)^{k + 1} \cdot \frac{\beta^{2 k + 1} - \alpha^{2 k + 1}}{\sqrt{- P}} = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
  
 +
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
== Ciągi Lucasa ==
 
  
<span style="font-size: 110%; font-weight: bold;">Definicja L16</span><br/>
 
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>U_n = U_n (P, Q)</math> i <math>V_n = V_n (P, Q)</math> definiujemy następująco
 
  
::<math>U_n = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}}</math>
+
<span style="font-size: 110%; font-weight: bold;">Zadanie N12</span><br/>
 +
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q + 1</math>, to
  
::<math>V_n = \alpha^n + \beta^n</math>
+
::<math>U_{2 k} (P, P Q) = P^k U_{2 k} (1, - Q)</math>
  
gdzie liczby
+
::<math>U_{2 k + 1} (P, P Q) = P^k V_{2 k + 1} (1, - Q)</math>
  
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}}</math>
+
::<math>V_{2 k} (P, P Q) = P^k V_{2 k} (1, - Q)</math>
  
::<math>\beta = {\small\frac{P - \sqrt{D}}{2}}</math>
+
::<math>V_{2 k + 1} (P, P Q) = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
  
są pierwiastkami równania <math>x^2 - P x + Q = 0</math>.
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Niech
  
 +
::<math>\alpha = {\small\frac{1 + \sqrt{P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{P}}{2}}</math>
  
 +
::<math>a = {\small\frac{P + \sqrt{P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{P}}{2}}</math>
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L17</span><br/>
+
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
Zauważmy, że:
 
  
::<math>P = \alpha + \beta</math>
+
::<math>x^2 - x - {\small\frac{P - 1}{4}} = 0</math>
  
::<math>Q = \alpha \beta</math>
+
::<math>x^2 - P x + {\small\frac{P (P - 1)}{4}} = 0</math>
  
::<math>\sqrt{D} = \alpha - \beta</math>
+
Z założenia <math>P = 4 Q + 1</math>, zatem
  
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>V_0 = 2</math> i <math>V_1 = P</math>
+
::<math>x^2 - x - Q = 0</math>
  
 +
::<math>x^2 - P x + P Q = 0</math>
  
Warunek <math>P^2 - 4 Q \neq 0</math> wyklucza następujące pary <math>(P, Q)</math>
+
Czyli definiują one ciągi Lucasa
  
::<math>(0, 0), (\pm 2, 1), (\pm 4, 4), (\pm 6, 9), (\pm 8, 16), (\pm 10, 25), (\pm 12, 36), ..., (\pm 2 n, n^2), ...</math>
+
::<math>U_n (1, - Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad V_n (1, - Q) = \alpha^n + \beta^n</math>
  
 +
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
  
 +
Zauważmy, że
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L18</span><br/>
+
::<math>\alpha - \beta = a - b = \sqrt{P}</math>
Oczywiście liczby <math>\alpha</math> i <math>\beta</math> są również pierwiastkami równania
 
  
::<math>x^{n + 2} - P x^{n + 1} + Q x^n = 0</math>
+
::<math>{\small\frac{a}{\alpha}} = {\small\frac{P + \sqrt{P}}{1 + \sqrt{P}}} = \sqrt{P}</math>
  
Wynika stąd, że ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math> spełniają równania rekurencyjne
+
::<math>{\small\frac{b}{\beta}} = {\small\frac{P - \sqrt{P}}{1 - \sqrt{P}}} = - \sqrt{P}</math>
  
::<math>\alpha^{n + 2} = P \alpha^{n + 1} - Q \alpha^n</math>
 
  
::<math>\beta^{n + 2} = P \beta^{n + 1} - Q \beta^n</math>
+
Łatwo znajdujemy
  
Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> spełniają identyczne równania rekurencyjne jak ciągi <math>(\alpha^n)</math> i <math>(\beta^n)</math>. Istotnie, odejmując i&nbsp;dodając stronami wypisane powyżej równania, otrzymujemy
+
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k} - \left( - \beta \sqrt{P} \right)^{2 k}}{\sqrt{P}} = \frac{P^k (\alpha^{2 k} - \beta^{2 k})}{\alpha - \beta} = P^k U_{2 k} (1, - Q)</math>
  
::<math>U_{n + 2} = P U_{n + 1} - Q U_n</math>
 
  
::<math>V_{n + 2} = P V_{n + 1} - Q V_n</math>
+
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k + 1} - \left( - \beta \sqrt{P} \right)^{2 k + 1}}{\sqrt{P}} = P^k (\alpha^{2 k + 1} + \beta^{2 k + 1}) = P^k V_{2 k + 1} (1, - Q)</math>
  
Dlatego możemy zdefiniować ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> w&nbsp;sposób równoważny
 
  
 +
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \alpha \sqrt{P} \right)^{2 k} + \left( - \beta \sqrt{P} \right)^{2 k} = P^k (\alpha^{2 k} + \beta^{2 k}) = P^k V_{2 k} (1, - Q)</math>
  
  
<span style="font-size: 110%; font-weight: bold;">Definicja L19</span><br/>
+
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \alpha \sqrt{P} \right)^{2 k + 1} + \left( - \beta \sqrt{P} \right)^{2 k + 1} = P^{k + 1} \cdot \frac{\alpha^{2 k + 1} - \beta^{2 k + 1}}{\sqrt{P}} = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
Niech <math>P, Q \in \mathbb{Z} \setminus \{0\}</math> oraz <math>D = P^2 - 4 Q \neq 0</math>. Ciągi Lucasa <math>(U_n)</math> i <math>(V_n)</math> określone są następującymi wzorami rekurencyjnymi
 
  
::<math>U_0 = 0</math>, <math>U_1 = 1</math>, <math>U_n = P U_{n - 1} - Q U_{n - 2}</math>
+
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
::<math>V_0 = 2</math>, <math>V_1 = P</math>, <math>V_n = P V_{n - 1} - Q V_{n - 2}</math>
 
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N13</span><br/>
 +
Dla wyrazów ciągów Lucasa prawdziwe są wzory
  
<span style="font-size: 110%; font-weight: bold;">Przykład L20</span><br/>
+
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
Początkowe wyrazy ciągów Lucasa
+
|-
 
+
| <math>1.</math> || <math>U_{m + n} = U_m U_{n + 1} - Q U_{m - 1} U_n</math> ||
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: left; margin-right: auto;"
 
 
|-
 
|-
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{U_n (P, Q)}</math> !! <math>\boldsymbol{V_n (P, Q)}</math>
+
| <math>2.</math> || <math>V_{m + n} = V_m V_n - Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
|-
| &nbsp;&nbsp;<math>0</math>&nbsp;&nbsp; || <math>0</math> || <math>2</math>
+
| <math>3.</math> || <math>U_{m + n} = U_m V_n - Q^n U_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
|-
| &nbsp;&nbsp;<math>1</math>&nbsp;&nbsp; || <math>1</math> || <math>P</math>
+
| <math>4.</math> || <math>V_{m + n} = D U_m U_n + Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
|-
| &nbsp;&nbsp;<math>2</math>&nbsp;&nbsp; || <math>P</math> || <math>P^2 - 2 Q</math>
+
| <math>5.</math> || <math>U_m V_n - V_m U_n = 2 Q^n U_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
|-
| &nbsp;&nbsp;<math>3</math>&nbsp;&nbsp; || <math>P^2 - Q</math> || <math>P^3 - 3 P Q</math>
+
| <math>6.</math> || <math>U^2_n = U_{n - 1} U_{n + 1} + Q^{n - 1}</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>4</math>&nbsp;&nbsp; || <math>P^3 - 2 P Q</math> || <math>P^4 - 4 P^2 Q + 2 Q^2</math>
+
| <math>7.</math> || <math>V^2_n = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math> ||  
 +
|}
 +
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 
|-
 
|-
| &nbsp;&nbsp;<math>5</math>&nbsp;&nbsp; || <math>P^4 - 3 P^2 Q + Q^2</math> || <math>P^5 - 5 P^3 Q + 5 P Q^2</math>
+
| <math>\;\; 8.</math> || <math>2 U_{m + n} = U_m V_n + V_m U_n</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>6</math>&nbsp;&nbsp; || <math>P^5 - 4 P^3 Q + 3 P Q^2</math> || <math>P^6 - 6 P^4 Q + 9 P^2 Q^2 - 2 Q^3</math>
+
| <math>\;\; 9.</math> || <math>2 V_{m + n} = V_m V_n + D U_m U_n</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>7</math>&nbsp;&nbsp; || <math>P^6 - 5 P^4 Q + 6 P^2 Q^2 - Q^3</math> || <math>P^7 - 7 P^5 Q + 14 P^3 Q^2 - 7 P Q^3</math>
+
| <math>10.</math> || <math>V_m V_n - D U_m U_n = 2 Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
|-
| &nbsp;&nbsp;<math>8</math>&nbsp;&nbsp; || <math>P^7 - 6 P^5 Q + 10 P^3 Q^2 - 4 P Q^3</math> || <math>P^8 - 8 P^6 Q + 20 P^4 Q^2 - 16 P^2 Q^3 + 2 Q^4</math>
+
| <math>11.</math> || <math>U_{2 n} = U_n V_n</math> ||  
 
|-
 
|-
| &nbsp;&nbsp;<math>9</math>&nbsp;&nbsp; || <math>P^8 - 7 P^6 Q + 15 P^4 Q^2 - 10 P^2 Q^3 + Q^4</math> || <math>P^9 - 9 P^7 Q + 27 P^5 Q^2 - 30 P^3 Q^3 + 9 P Q^4</math>
+
| <math>12.</math> || <math>V_{2 n} = V^2_n - 2 Q^n</math> ||
 +
|-
 +
| <math>13.</math> || <math>V_{2 n} = D U^2_n + 2 Q^n</math> ||
 +
|-
 +
| <math>14.</math> || <math>V^2_n - D U^2_n = 4 Q^n</math> ||
 +
|-
 +
| <math>15.</math> || <math>D U_n = 2 V_{n + 1} - P V_n</math> ||
 +
|-
 +
| <math>16.</math> || <math>V_n = 2 U_{n + 1} - P U_n</math> ||
 +
|-
 +
| <math>17.</math> || <math>D U_n = V_{n + 1} - Q V_{n - 1}</math> || <math>n \geqslant 1</math>
 +
|-
 +
| <math>18.</math> || <math>V_n = U_{n + 1} - Q U_{n - 1}</math> || <math>n \geqslant 1</math>
 +
|}
 +
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 +
|-
 +
| <math>19.</math> || <math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
 +
|-
 +
| <math>20.</math> || <math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
 +
|-
 +
| <math>21.</math> || <math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
 
|}
 
|}
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
'''Wzory 1. - 7. najłatwiej udowodnić korzystając z&nbsp;definicji N1.'''
  
 +
Wzór 1.
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L21</span><br/>
+
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
W PARI/GP możemy napisać prosty kod, który pozwoli obliczyć wartości wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
 
  
<span style="font-size: 90%; color:black;">LucasU(n, P, Q) = '''if'''( n == 0, 0, '''if'''( n == 1, 1, P*LucasU(n-1, P, Q) - Q*LucasU(n-2, P, Q) ) )</span>
+
:::<math>\quad \: = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} - \alpha \beta \cdot {\small\frac{\alpha^{m - 1} - \beta^{m - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
  
<span style="font-size: 90%; color:black;">LucasV(n, P, Q) = '''if'''( n == 0, 2, '''if'''( n == 1, P, P*LucasV(n-1, P, Q) - Q*LucasV(n-2, P, Q) ) )</span>
+
:::<math>\quad \: = U_m U_{n + 1} - Q U_{m - 1} U_n</math>
  
  
 +
Wzór 2.
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L22</span><br/>
+
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
Niech <math>D = P^2 - 4 Q</math>. Wyrazy ciągów Lucasa można przedstawić w&nbsp;postaci sumy
 
  
::<math>2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
+
:::<math>\quad \;\! = (\alpha^m + \beta^m) (\alpha^n + \beta^n) - \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
  
::<math>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
+
:::<math>\quad \;\! = V_m V_n - Q^n V_{m - n}</math>
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
 
  
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
+
Wzór 3.
  
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
+
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
  
Obliczając sumę powyższych wzorów, otrzymujemy
+
:::<math>\quad \: = {\small\frac{(\alpha^m - \beta^m) (\alpha^n + \beta^n)}{\alpha - \beta}} - {\small\frac{\alpha^n \beta^n \cdot (\alpha^{m - n} - \beta^{m - n})}{\alpha - \beta}}</math>
  
::<math>2^n (\alpha^n + \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j + (- \delta)^j)</math>
+
:::<math>\quad \: = U_m V_n - Q^n U_{m - n}</math>
  
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} \cdot 2 \delta^{2 k}</math>
 
  
:::::<math>\quad \: = 2 \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
+
Wzór 4.
  
gdzie <math>j = 2 k</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor n / 2 \rfloor</math>
+
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
  
Zatem
+
:::<math>\quad \;\! = (\alpha - \beta)^2 \cdot {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} + \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
  
::<math>2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k</math>
+
:::<math>\quad \;\! = D U_m U_n + Q^n V_{m - n}</math>
  
  
Obliczając różnicę tych wzorów, mamy
+
Wzór 5.
  
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j)</math>
+
::<math>U_m V_n - V_m U_n = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot (\alpha^n + \beta^n) - (\alpha^m + \beta^m) \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
  
:::::<math>\quad \: = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} \cdot 2 \delta^{2 k + 1}</math>
+
::::::<math>\;\;\: = 2 \cdot \alpha^n \beta^n \cdot {\small\frac{\alpha^{m - n} - \beta^{m - n}}{\alpha - \beta}}</math>
  
:::::<math>\quad \: = 2 \delta \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
+
::::::<math>\;\;\: = 2 Q^n U_{m - n}</math>
  
gdzie <math>j = 2 k + 1</math> i&nbsp;sumowanie przebiega od <math>k = 0</math> do <math>k = \lfloor (n - 1) / 2 \rfloor</math>
 
  
 +
Wzór 6.
  
Zatem
+
::<math>U^2_n = \left( {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \right)^2</math>
  
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} = 2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
+
:::<math>\;\! = {\small\frac{\alpha^{n - 1} - \beta^{n - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} + \alpha^{n - 1} \beta^{n - 1}</math>
  
Co należało pokazać.<br/>
+
:::<math>\;\! = U_{n - 1} U_{n + 1} + Q^{n - 1}</math>
&#9633;
 
{{\Spoiler}}
 
  
  
 +
Wzór 7.
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L23</span><br/>
+
::<math>V^2_n = (\alpha^n + \beta^n)^2</math>
Korzystając z&nbsp;twierdzenia L22, możemy napisać proste funkcje do znajdowania postaci kolejnych wyrazów <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math>
 
  
<span style="font-size: 90%; color:black;">U(n) = 2^(1 - n)*'''sum'''(k=0, '''floor'''((n-1)/2), '''binomial'''(n, 2*k+1) * P^(n-2*k-1) * (P^2-4*Q)^k)</span>
+
:::<math>\;\! = (\alpha^{n - 1} + \beta^{n - 1}) (\alpha^{n + 1} + \beta^{n + 1}) - (\alpha - \beta)^2 \cdot \alpha^{n - 1} \beta^{n - 1}</math>
  
<span style="font-size: 90%; color:black;">V(n) = 2^(1 - n)*'''sum'''(k=0, '''floor'''(n/2), '''binomial'''(n, 2*k) * P^(n-2*k) * (P^2-4*Q)^k)</span>
+
:::<math>\;\! = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math>
  
  
 +
'''Wzory 8. - 18. można łatwo udowodnić, korzystając ze wzorów 1. - 7.'''
  
Często możemy spotkać założenie <math>P \geqslant 1</math>. Poniższe twierdzenie wyjaśnia, dlaczego tak jest.
+
Wzór 8. Policzyć sumę wzoru 3. pomnożonego przez <math>2</math> i&nbsp;wzoru 5.
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L24</span><br/>
+
Wzór 9. Policzyć sumę wzorów 2. i 4.
Jeżeli <math>(U_n)</math> i <math>(V_n)</math> są ciągami Lucasa, to
 
  
::<math>U_n (- P, Q) = (- 1)^{n - 1} U_n (P, Q)</math>
+
Wzór 10. Połączyć wzory 2. i 4.
  
::<math>V_n (- P, Q) = (- 1)^n V_n (P, Q)</math>
+
Wzór 11. We wzorze 3. położyć <math>m = n</math>.
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
Wzór 12. We wzorze 2. położyć <math>m = n</math>.
Niech
 
  
::<math>\alpha = \frac{P + \sqrt{D}}{2} \qquad \qquad \;\; \beta = \frac{P - \sqrt{D}}{2}</math>
+
Wzór 13. We wzorze 4. położyć <math>m = n</math>.
  
::<math>a = \frac{- P + \sqrt{D}}{2} \qquad \qquad b = \frac{- P - \sqrt{D}}{2}</math>
+
Wzór 14. We wzorze 10. położyć <math>m = n</math> lub połączyć wzory 12. i 13.
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
Wzór 15. We wzorze 9. położyć <math>m = 1</math>.
  
::<math>x^2 - P x + Q = 0</math>
+
Wzór 16. We wzorze 8. położyć <math>m = 1</math>.
  
::<math>x^2 + P x + Q = 0</math>
+
Wzór 17. We wzorze 15. położyć <math>V_{n + 1} = P V_n - Q V_{n - 1}</math>.
  
Zatem definiują one ciągi Lucasa
+
Wzór 18. We wzorze 16. położyć <math>U_{n + 1} = P U_n - Q U_{n - 1}</math>.
  
::<math>U_n (P, Q) = \frac{\alpha^n - \beta^n}{\alpha - \beta} \qquad \qquad \;\; V_n (P, Q) = \alpha^n + \beta^n</math>
 
  
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} \qquad \qquad V_n (- P, Q) = a^n + b^n</math>
+
'''Wzory 19. - 21. to wzory, które wykorzystamy w&nbsp;przyszłości do szybkiego obliczania wartości wyrazów <math>U_n</math> i <math>V_n</math> modulo.'''
  
Zauważmy, że
+
Wzór 19. Wystarczy połączyć wzory 11. oraz 16.
  
::<math>\alpha - \beta = a - b = \sqrt{D}</math>
+
Wzór 20. Wystarczy we wzorze 1. położyć <math>m = n + 1</math>.
  
::<math>\frac{a}{\beta} = \frac{b}{\alpha} = - 1</math>
+
Wzór 21. Kładąc we wzorze 19. <math>n \rightarrow n + 1</math>, otrzymujemy
  
Łatwo znajdujemy
+
::<math>U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - P U^2_{n + 1} \qquad (*)</math>
  
::<math>U_n (- P, Q) = \frac{a^n - b^n}{a - b} = \frac{(- \beta)^n - (- \alpha)^n}{\sqrt{D}} = (- 1)^n \cdot \frac{\beta^n - \alpha^n}{\alpha - \beta} = (- 1)^{n - 1} \cdot U_n (P, Q)</math>
+
Kładąc we wzorze 1. <math>m = n + 2</math>, mamy
  
::<math>V_n (- P, Q) = a^n + b^n = (- \beta)^n + (- \alpha)^n = (- 1)^n \cdot (\alpha^n + \beta^n) = (- 1)^n \cdot V_n (P, Q)</math>
+
::<math>U_{2 n + 2} = U_{n + 2} U_{n + 1} - Q U_{n + 1} U_n</math>
  
Co należało pokazać.<br/>
+
Czyli
 +
 
 +
::<math>2 U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - 2 Q U_n U_{n + 1}</math>
 +
 
 +
Odejmując od powyższego wzoru wzór <math>(*)</math>, dostajemy wzór 21.
 +
 
 +
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
 +
 
 +
Co należało pokazać.<br/>
 
&#9633;
 
&#9633;
 
{{\Spoiler}}
 
{{\Spoiler}}
Linia 610: Linia 561:
  
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L25</span><br/>
 
Pokazać, że jeżeli <math>P, Q \in \mathbb{Z} \setminus \{ 0 \}</math> i <math>D = P^2 - 4 Q \neq 0</math>, to
 
  
::<math>U_n (2 P, 4 Q) = 2^{n - 1} U_n (P, Q)</math>
 
  
::<math>V_n (2 P, 4 Q) = 2^n V_n (P, Q)</math>
+
== Obliczanie wyrazów ciągu Lucasa modulo <math>m</math> ==
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
<span style="font-size: 110%; font-weight: bold;">Przykład N14</span><br/>
Niech
+
Pokażemy, jak wykorzystać podane w&nbsp;twierdzeniu N13 wzory 19, 20, 21 i 16
  
::<math>\alpha = {\small\frac{P + \sqrt{D}}{2}} \qquad \qquad \;\; \beta = {\small\frac{P - \sqrt{D}}{2}}</math>
+
::<math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
  
::<math>a = P + \sqrt{D} \qquad \qquad \;\; b = P - \sqrt{D}</math>
+
::<math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
  
::<math>x^2 - P x + Q = 0</math>
+
::<math>V_n = 2 U_{n + 1} - P U_n</math>
  
::<math>x^2 - 2 P x + 4 Q = 0</math>
+
do szybkiego obliczania wyrazów ciągu Lucasa modulo <math>m</math>.
  
Zatem definiują one ciągi Lucasa
 
  
::<math>U_n (P, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \;\;\; V_n (P, Q) = \alpha^n + \beta^n</math>
+
Niech <math>P = 3</math>, <math>Q = 1</math>, <math>D = P^2 - 4 Q = 5</math>, <math>n = 22 = (10110)_2 = \sum_{j = 0}^{4} a_j \cdot 2^j</math>.
  
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (2 P, 4 Q) = a^n + b^n</math>
+
W tabeli przedstawione są kolejne kroki, jakie musimy wykonać, aby policzyć <math>U_n = U_{22}</math> modulo <math>m = 23</math>.
  
Zauważmy, że
+
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
 +
|-
 +
! <math>\boldsymbol{j}</math> !! <math>\boldsymbol{a_j}</math> !! <math>\boldsymbol{k_j}</math> !! <math>\boldsymbol{U_{k_j}}</math> !! <math>\boldsymbol{U_{k_j + 1}}</math>
 +
|-
 +
| <math>4</math> || <math>1</math> || <math>(1)_2 = 1</math> || <math>U_1 = 1</math> || <math>U_2 = P = 3</math>
 +
|-
 +
| <math>3</math> || <math>0</math> || <math>(10)_2 = 2</math> || <math>U_2 = 2 U_1 U_2 - 3 U^2_1 = 6 - 3 = 3</math> || <math>U_3 = U^2_2 - 1 = 8</math>
 +
|-
 +
| <math>2</math> || <math>1</math> || <math>(101)_2 = 5</math> || <math>U_5 = U^2_3 - U^2_2 = 64 - 9 = 55 \equiv 9</math> || <math>U_6 = 3 U_3^2 - 2 U_2 U_3 = 192 - 48 = 144 \equiv 6</math>
 +
|-
 +
| <math>1</math> || <math>1</math> || <math>(1011)_2 = 11</math> || <math>U_{11} = U^2_6 - U^2_5 \equiv 36 - 81 \equiv - 45 \equiv 1</math> || <math>U_{12} = 3 U_6^2 - 2 U_5 U_6 \equiv 108 - 108 \equiv 0</math>
 +
|-
 +
| <math>0</math> || <math>0</math> || <math>(10110)_2 = 22</math> || <math>U_{22} = 2 U_{11} U_{12} - 3 U^2_{11} \equiv 0 - 3 \equiv 20</math> || <math>U_{23} = U^2_{12} - U^2_{11} \equiv 0 - 1 \equiv 22</math>
 +
|}
  
::<math>\alpha - \beta = \sqrt{D}</math>
+
W kolumnie <math>a_j</math> wypisujemy kolejne cyfry liczby <math>n = 22 = (10110)_2</math> zapisanej w&nbsp;układzie dwójkowym. Liczby w&nbsp;kolumnie <math>k_j</math> tworzymy, biorąc kolejne (od prawej do lewej) cyfry liczby <math>n</math> w&nbsp;zapisie dwójkowym. Postępując w&nbsp;ten sposób, w&nbsp;ostatnim wierszu mamy <math>k_j = n</math> i&nbsp;wyliczamy liczby <math>U_n</math> i <math>U_{n + 1}</math> modulo <math>m</math>.
  
::<math>a - b = 2 \sqrt{D}</math>
+
Dla uproszczenia zapisu i&nbsp;ułatwienia zrozumienia liczbę <math>k_j</math> oznaczymy jako <math>r</math>, a <math>k_{j + 1}</math> jako <math>s</math>. Zauważmy, że
  
::<math>{\small\frac{a}{\alpha}} = {\small\frac{b}{\beta}} = 2</math>
+
:* tabela jest zbudowana tak, że musimy znaleźć wyrazy ciągu Lucasa o&nbsp;indeksie <math>r = k_j</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>r + 1 = k_j + 1</math>
 +
:* przejście do następnego wiersza (w dół) oznacza, że musimy znaleźć wyrazy o&nbsp;indeksie <math>s = k_{j + 1}</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>s + 1</math>
 +
:* przechodząc do następnego wiersza, dotychczasowa liczba <math>r = k_j</math> powiększa się o&nbsp;kolejną cyfrę ( <math>0</math> lub <math>1</math> ), którą dopisujemy z&nbsp;prawej strony
 +
:* dodanie na końcu liczby <math>r = k_j</math> zera podwaja liczbę <math>r</math>, czyli <math>s = k_{j + 1} = 2 r</math> oraz <math>s + 1 = 2 r + 1</math>
 +
:* dodanie na końcu liczby <math>r = k_j</math> jedynki podwaja liczbę <math>r</math> i&nbsp;zwiększą ją o&nbsp;jeden, czyli <math>s = k_{j + 1} = 2 r + 1</math> oraz <math>s + 1 = 2 r + 2</math>
  
Łatwo znajdujemy
 
  
::<math>U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} = {\small\frac{(2 \alpha)^n - (2 \beta)^n}{2 \sqrt{D}}} = 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = 2^{n - 1} U_n (P, Q)</math>
+
Dlatego, jeżeli kolejną dodaną cyfrą jest zero, to korzystamy ze wzorów
  
::<math>V_n (2 P, 4 Q) = a^n + b^n = (2 \alpha)^n + (2 \beta)^n = 2^n (\alpha^n + \beta^n) = 2^n V_n (P, Q)</math>
+
::<math>U_s = U_{2 r} = 2 U_r U_{r + 1} - P U^2_r</math>
  
Co należało pokazać.<br/>
+
::<math>U_{s + 1} = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
Gdy kolejną dodaną cyfrą jest jeden, to stosujemy wzory
  
 +
::<math>U_s = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L26</span><br/>
+
::<math>U_{s + 1} = U_{2 r + 2} = P U^2_{r + 1} - 2 Q U_r U_{r + 1}</math>
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q - 1</math>, to
 
  
::<math>U_{2 k} (P, P Q) = - (- P)^k U_{2 k} (1, Q)</math>
 
  
::<math>U_{2 k + 1} (P, P Q) = (- P)^k V_{2 k + 1} (1, Q)</math>
+
Korzystając ze wzoru <math>V_n = 2 U_{n + 1} - P U_n</math>, mamy
  
::<math>V_{2 k} (P, P Q) = (- P)^k V_{2 k} (1, Q)</math>
+
::<math>V_{22} = 2 U_{23} - 3 U_{22} \equiv 44 - 60 \equiv - 16 \equiv 7 \pmod{23}</math>
  
::<math>V_{2 k + 1} (P, P Q) = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
+
Ostatecznie otrzymujemy
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
::<math>U_{22} \equiv 20 \pmod{23} \quad</math> oraz <math>\quad V_{22} \equiv 7 \pmod{23}</math>
Niech
 
  
::<math>\alpha = {\small\frac{1 + \sqrt{- P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{- P}}{2}}</math>
 
  
::<math>a = {\small\frac{P + \sqrt{- P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{- P}}{2}}</math>
 
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N15</span><br/>
 +
Uogólniając postępowanie przedstawione w&nbsp;przykładzie N14, możemy napisać program w&nbsp;PARI/GP do szybkiego obliczania wyrazów ciągu Lucasa <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math> modulo <math>m</math>.
  
::<math>x^2 - x + {\small\frac{P + 1}{4}} = 0</math>
+
<span style="font-size: 90%; color:black;">modLucas(n, P, Q, m) =
 
+
{
::<math>x^2 - P x + {\small\frac{P (P + 1)}{4}} = 0</math>
+
'''local'''(A, i, s, U,&#32;U2, V, W,&#32;W2);
 
+
'''if'''( m == 1, '''return'''([0, 0]) );
Z założenia <math>P = 4 Q - 1</math>, zatem
+
'''if'''( n == 0, '''return'''([0, 2 % m]) );
 +
A = '''digits'''(n, 2); \\ otrzymujemy wektor cyfr liczby n w układzie dwójkowym
 +
s = '''length'''(A); \\ długość wektora A
 +
U = 1;
 +
W = P;
 +
i = 1;
 +
'''while'''( i++ <= s,
 +
        '''if'''( A[i] == 0,  U2 = 2*U*W - P*U^2;  W2 = W^2 - Q*U^2 );
 +
        '''if'''( A[i] == 1,  U2 = W^2 - Q*U^2;  W2 = P*W^2 - 2*Q*U*W );
 +
        U = U2 % m;
 +
        W = W2 % m;
 +
      );
 +
V = (2*W - P*U) % m;
 +
'''return'''([U, V]);
 +
}</span>
  
::<math>x^2 - x + Q = 0</math>
 
  
::<math>x^2 - P x + P Q = 0</math>
 
  
Czyli definiują one ciągi Lucasa
 
  
::<math>U_n (1, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \:\:\: V_n (1, Q) = \alpha^n + \beta^n</math>
 
  
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
+
== Podzielność wyrazów <math>U_n (P, Q)</math> przez liczbę pierwszą nieparzystą ==
  
Zauważmy, że
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N16</span><br/>
 +
Niech <math>p</math> będzie liczbą pierwszą nieparzystą. W&nbsp;przypadku, gdy <math>p \nmid P Q</math> nie możemy nic powiedzieć o&nbsp;podzielności wyrazów <math>U_n</math> przez <math>p</math>. Przykładowo, jeżeli <math>P \equiv 1 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math>, mamy
  
::<math>\alpha - \beta = a - b = \sqrt{- P}</math>
+
::<math>(U_n) \equiv (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, \ldots)</math>
  
::<math>{\small\frac{a}{\beta}} = {\small\frac{P + \sqrt{- P}}{1 - \sqrt{- P}}} = \sqrt{- P}</math>
+
W przypadku, gdy <math>P \equiv 2 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math> mamy
  
::<math>{\small\frac{b}{\alpha}} = {\small\frac{P - \sqrt{- P}}{1 + \sqrt{- P}}} = - \sqrt{- P}</math>
+
::<math>(U_n) \equiv (0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, \ldots)</math>
  
 +
Sytuacja wygląda inaczej, gdy <math>p \mid P Q</math>.
  
Łatwo znajdujemy
 
  
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k} - \left( - \alpha \sqrt{- P} \right)^{2 k}}{\sqrt{- P}} = \frac{(- P)^k (\beta^{2 k} - \alpha^{2 k})}{\alpha - \beta} = - (- P)^k U_{2 k} (1, Q)</math>
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N17</span><br/>
 +
Niech <math>p</math> będzie liczbą pierwszą nieparzystą.
  
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k + 1} - \left( - \alpha \sqrt{- P} \right)^{2 k + 1}}{\sqrt{- P}} = (- P)^k (\beta^{2 k + 1} + \alpha^{2 k + 1}) = (- P)^k V_{2 k + 1} (1, Q)</math>
+
::{| border="0"
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \mid P \;</math> <math>\text{i} \;\; p \mid Q , \;</math> to <math>\; p \mid U_n \;</math> dla <math>n \geqslant 2</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \mid P \;</math> <math>\text{i} \;\; p \nmid Q , \;</math> to <math>\; p \mid U_{2 n} \;</math> i <math>\; p \nmid U_{2 n + 1}</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \mid Q , \;</math> to <math>\; p \nmid U_n \;</math> dla <math>n \geqslant 1</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \mid Q , \;</math> to <math>\; p \mid U_n</math>, gdzie <math>n \geqslant 2</math>, wtedy i&nbsp;tylko wtedy, gdy <math>\; p \mid P</math>
 +
|-style=height:1.9em
 +
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \mid D , \;</math> to <math>\; p \mid U_n \;</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \mid n</math>
 +
|}
  
 +
Założenie, że <math>p \nmid P</math> w&nbsp;ostatnim punkcie jest istotne. Gdy <math>\; p \mid P \;</math> i <math>\; p \mid D , \;</math> to <math>\; p \mid Q \;</math> i&nbsp;otrzymujemy punkt pierwszy.
  
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \beta \sqrt{- P} \right)^{2 k} + \left( - \alpha \sqrt{- P} \right)^{2 k} = (- P)^k (\alpha^{2 k} + \beta^{2 k}) = (- P)^k V_{2 k} (1, Q)</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
'''Punkt 1.'''
  
 +
Ponieważ <math>U_2 = P</math>, zatem <math>p \mid U_2</math>. Dla <math>n \geqslant 3</math> wyrażenie <math>U_n = P U_{n - 1} - Q U_{n - 2}</math> jest podzielne przez <math>p</math>.
  
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \beta \sqrt{- P} \right)^{2 k + 1} + \left( - \alpha \sqrt{- P} \right)^{2 k + 1} = (- P)^{k + 1} \cdot \frac{\beta^{2 k + 1} - \alpha^{2 k + 1}}{\sqrt{- P}} = - (- P)^{k + 1} U_{2 k + 1} (1, Q)</math>
+
'''Punkt 2.'''
  
Co należało pokazać.<br/>
+
Indeksy parzyste. Indukcja matematyczna. Mamy <math>U_0 = 0</math> i <math>U_2 = P</math>, zatem <math>p \mid U_0</math> i <math>p \mid U_2</math>. Zakładając, że <math>p \mid U_{2 n}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 2}</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
::<math>U_{2 n + 2} = P U_{2 n - 1} - Q U_{2 n}</math>
  
 +
Z założenia indukcyjnego wynika, że <math>p \mid U_{2 n + 2}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 0</math>.
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L27</span><br/>
+
Indeksy nieparzyste. Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_3 = P^2 - Q</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_3</math>. Zakładając, że <math>p \nmid U_{2 n - 1}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 1}</math>
Pokazać, że jeżeli <math>Q \in \mathbb{Z} \setminus \{ 0 \}</math> oraz <math>P = 4 Q + 1</math>, to
 
  
::<math>U_{2 k} (P, P Q) = P^k U_{2 k} (1, - Q)</math>
+
::<math>U_{2 n + 1} = P U_{2 n} - Q U_{2 n - 1}</math>
  
::<math>U_{2 k + 1} (P, P Q) = P^k V_{2 k + 1} (1, - Q)</math>
+
Z założenia indukcyjnego wynika, że <math>p \nmid U_{2 n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 1</math>.
  
::<math>V_{2 k} (P, P Q) = P^k V_{2 k} (1, - Q)</math>
+
'''Punkt 3.'''
  
::<math>V_{2 k + 1} (P, P Q) = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
+
Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_2 = P</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_2</math>. Zakładając, że <math>p \nmid U_n</math> zachodzi dla wszystkich liczb całkowitych dodatnich nie większych od <math>n</math>, z&nbsp;definicji ciągu <math>(U_n)</math>
 +
otrzymujemy dla <math>n + 1</math>
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
::<math>U_{n + 1} = P U_n - Q U_{n - 1}</math>
Niech
 
  
::<math>\alpha = {\small\frac{1 + \sqrt{P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{P}}{2}}</math>
+
Z założenia indukcyjnego wynika, że <math>p \nmid U_{n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich liczb <math>n \geqslant 1</math>.
  
::<math>a = {\small\frac{P + \sqrt{P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{P}}{2}}</math>
+
'''Punkt 4.'''
  
Liczby <math>\alpha, \beta</math> oraz <math>a, b</math> są odpowiednio pierwiastkami równań
+
Wynika z&nbsp;punktów pierwszego i&nbsp;trzeciego.
  
::<math>x^2 - x - {\small\frac{P - 1}{4}} = 0</math>
+
'''Punkt 5.'''
  
::<math>x^2 - P x + {\small\frac{P (P - 1)}{4}} = 0</math>
+
Z twierdzenia N7 wiemy, że
  
Z założenia <math>P = 4 Q + 1</math>, zatem
+
::<math>2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
  
::<math>x^2 - x - Q = 0</math>
+
::::<math>\;\; = n P^{n - 1} + \binom{n}{3} P^{n - 3} D + \binom{n}{5} P^{n - 5} D^2 + \ldots +
 +
\begin{cases}
 +
n P D^{(n - 2) / 2} & \text{gdy }n\text{ jest parzyste} \\
 +
D^{(n - 1) / 2} & \text{gdy }n\text{ jest nieparzyste} \\
 +
\end{cases}</math>
  
::<math>x^2 - P x + P Q = 0</math>
+
Z założenia <math>p \mid D</math>, zatem modulo <math>p</math> dostajemy
  
Czyli definiują one ciągi Lucasa
+
::<math>2^{n - 1} U_n \equiv n P^{n - 1} \pmod{p}</math>
  
::<math>U_n (1, - Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad V_n (1, - Q) = \alpha^n + \beta^n</math>
+
Ponieważ <math>p \nmid P</math>, zatem <math>p \mid U_n</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \mid n</math>.
 +
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
::<math>U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n</math>
 
  
Zauważmy, że
 
  
::<math>\alpha - \beta = a - b = \sqrt{P}</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N18</span><br/>
 +
Jeżeli <math>d</math> jest nieparzystym dzielnikiem <math>Q</math>, to dla <math>n \geqslant 2</math> jest
  
::<math>{\small\frac{a}{\alpha}} = {\small\frac{P + \sqrt{P}}{1 + \sqrt{P}}} = \sqrt{P}</math>
+
::<math>U_n \equiv P^{n - 1} \pmod{d}</math>
  
::<math>{\small\frac{b}{\beta}} = {\small\frac{P - \sqrt{P}}{1 - \sqrt{P}}} = - \sqrt{P}</math>
+
W szczególności, gdy liczba pierwsza nieparzysta <math>p</math> jest dzielnikiem <math>Q</math> i <math>p \nmid P</math>, to
 +
 
 +
::<math>U_p \equiv 1 \pmod{p}</math>
 +
 
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
  
 +
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
  
Łatwo znajdujemy
+
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
  
::<math>U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k} - \left( - \beta \sqrt{P} \right)^{2 k}}{\sqrt{P}} = \frac{P^k (\alpha^{2 k} - \beta^{2 k})}{\alpha - \beta} = P^k U_{2 k} (1, - Q)</math>
 
  
 +
Obliczając różnicę wyjściowych wzorów, mamy
  
::<math>U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k + 1} - \left( - \beta \sqrt{P} \right)^{2 k + 1}}{\sqrt{P}} = P^k (\alpha^{2 k + 1} + \beta^{2 k + 1}) = P^k V_{2 k + 1} (1, - Q)</math>
+
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) =</math>
  
 +
:::::<math>\quad \: = \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot 2 \delta^j</math>
  
::<math>V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \alpha \sqrt{P} \right)^{2 k} + \left( - \beta \sqrt{P} \right)^{2 k} = P^k (\alpha^{2 k} + \beta^{2 k}) = P^k V_{2 k} (1, - Q)</math>
+
:::::<math>\quad \: = 2 \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot \delta \cdot D^{(j - 1) / 2}</math>
  
 +
Rozpatrując powyższą równość modulo <math>Q</math> dostajemy (zobacz N43)
  
::<math>V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \alpha \sqrt{P} \right)^{2 k + 1} + \left( - \beta \sqrt{P} \right)^{2 k + 1} = P^{k + 1} \cdot \frac{\alpha^{2 k + 1} - \beta^{2 k + 1}}{\sqrt{P}} = P^{k + 1} U_{2 k + 1} (1, - Q)</math>
+
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\delta}} = 2^{n - 1} U_n \equiv \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot P^{j - 1}</math>
  
Co należało pokazać.<br/>
+
:::::::::<math>\;\:\: \equiv P^{n - 1} \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j}</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
:::::::::<math>\;\:\: \equiv 2^{n - 1} P^{n - 1}</math>
  
 +
Czyli
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L28</span><br/>
+
::<math>2^{n - 1} (U_n - P^{n - 1}) \equiv 0 \pmod{Q}</math>
Dla wyrazów ciągów Lucasa prawdziwe są wzory
 
  
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
+
Ponieważ <math>Q</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>, to tym bardziej <math>d</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>. Z założenia <math>\gcd (d, 2^{n - 1}) = 1</math>, zatem <math>d</math> dzieli <math>U_n - P^{n - 1}</math> (zobacz C74).
|-
+
 
| <math>1.</math> || <math>U_{m + n} = U_m U_{n + 1} - Q U_{m - 1} U_n</math> ||
+
W przypadku szczególnym, gdy <math>d = p</math>, gdzie <math>p</math> jest nieparzystą liczbą pierwszą i <math>p \nmid P</math>, z&nbsp;twierdzenia Fermata otrzymujemy natychmiast
|-
+
 
| <math>2.</math> || <math>V_{m + n} = V_m V_n - Q^n V_{m - n}</math> || <math>m \geqslant n</math>
+
::<math>U_p \equiv P^{p - 1} \equiv 1 \pmod{p}</math>
|-
+
 
| <math>3.</math> || <math>U_{m + n} = U_m V_n - Q^n U_{m - n}</math> || <math>m \geqslant n</math>
+
Co należało pokazać.<br/>
|-
+
&#9633;
| <math>4.</math> || <math>V_{m + n} = D U_m U_n + Q^n V_{m - n}</math> || <math>m \geqslant n</math>
+
{{\Spoiler}}
|-
+
 
| <math>5.</math> || <math>U_m V_n - V_m U_n = 2 Q^n U_{m - n}</math> || <math>m \geqslant n</math>
+
 
|-
+
 
| <math>6.</math> || <math>U^2_n = U_{n - 1} U_{n + 1} + Q^{n - 1}</math> ||
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N19</span><br/>
|-
+
Niech <math>D = P^2 - 4 Q</math>, a <math>(D \mid p)</math> oznacza symbol Legendre'a, gdzie <math>p</math> jest liczbą pierwszą nieparzystą i <math>p \nmid Q</math>. Mamy
| <math>7.</math> || <math>V^2_n = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math> ||
+
 
|}
+
::{| border="0"
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
+
|-style=height:2em
|-
+
| &#9679;&nbsp;&nbsp;&nbsp; <math>U_p \equiv (D \mid p) \pmod{p}</math>
| <math>\;\; 8.</math> || <math>2 U_{m + n} = U_m V_n + V_m U_n</math> ||
+
|-style=height:2em
|-
+
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \mid p) = - 1 , \;</math> to <math>\; p \mid U_{p + 1}</math>
| <math>\;\; 9.</math> || <math>2 V_{m + n} = V_m V_n + D U_m U_n</math> ||
+
|-style=height:2em
|-
+
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \mid p) = 1 , \;</math> to <math>\; p \mid U_{p - 1}</math>
| <math>10.</math> || <math>V_m V_n - D U_m U_n = 2 Q^n V_{m - n}</math> || <math>m \geqslant n</math>
 
|-
 
| <math>11.</math> || <math>U_{2 n} = U_n V_n</math> ||
 
|-
 
| <math>12.</math> || <math>V_{2 n} = V^2_n - 2 Q^n</math> ||
 
|-
 
| <math>13.</math> || <math>V_{2 n} = D U^2_n + 2 Q^n</math> ||
 
|-
 
| <math>14.</math> || <math>V^2_n - D U^2_n = 4 Q^n</math> ||
 
|-
 
| <math>15.</math> || <math>D U_n = 2 V_{n + 1} - P V_n</math> ||
 
|-
 
| <math>16.</math> || <math>V_n = 2 U_{n + 1} - P U_n</math> ||
 
|-
 
| <math>17.</math> || <math>D U_n = V_{n + 1} - Q V_{n - 1}</math> || <math>n \geqslant 1</math>
 
|-
 
| <math>18.</math> || <math>V_n = U_{n + 1} - Q U_{n - 1}</math> || <math>n \geqslant 1</math>
 
|}
 
{| class="wikitable plainlinks"  style="display: inline-table; margin-left: 5px; margin-right: 50px; font-size: 100%; text-align: left;"
 
|-
 
| <math>19.</math> || <math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
 
|-
 
| <math>20.</math> || <math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
 
|-
 
| <math>21.</math> || <math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
 
 
|}
 
|}
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
'''Wzory 1. - 7. najłatwiej udowodnić korzystając z&nbsp;definicji L16.'''
+
'''Punkt 1.'''
 +
 
 +
Zauważmy, że przypadek gdy <math>p \mid Q</math>, omówiliśmy w&nbsp;twierdzeniu poprzednim. Z&nbsp;założenia <math>p</math> jest liczbą pierwszą nieparzystą. Z&nbsp;twierdzenia N7, w&nbsp;przypadku nieparzystego <math>n = p</math>, otrzymujemy
 +
 
 +
::<math>2^{p - 1} U_p = p P^{p - 1} + \binom{p}{3} P^{p - 3} D + \binom{p}{5} P^{p - 5} D^2 + \ldots + \binom{p}{p-2} P^2 D^{(p - 3) / 2} + D^{(p - 1) / 2}</math>
 +
 
 +
Ponieważ dla każdego <math>k \in [1, p - 1]</math> (zobacz N43)
 +
 
 +
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
 +
 
 +
to modulo <math>p</math> dostajemy (zobacz J33)
 +
 
 +
::<math>2^{p - 1} U_p \equiv U_p \equiv D^{(p - 1) / 2} \equiv (D \mid p) \pmod{p}</math>
 +
 
 +
'''Punkt 2.'''
 +
 
 +
Zauważmy, że warunek <math>(D \mid p) = - 1</math> nie może być spełniony, gdy <math>p \mid Q</math>. Istotnie, gdy <math>p \mid Q</math>, to <math>D = P^2 - 4 Q \equiv P^2 \pmod{p}</math>, czyli
 +
 
 +
::<math>(D \mid p) = (P^2 \mid p) = (P \mid p)^2 = 0 , \;</math> gdy <math>p \mid P</math>
 +
 
 +
lub
 +
 
 +
::<math>(D \mid p) = (P^2 \mid p) = (P \mid p)^2 = 1 , \;</math> gdy <math>p \nmid P</math>
  
Wzór 1.
+
i nie może być <math>(D \mid p) = - 1</math>.
  
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
+
Dla parzystego <math>n = p + 1</math> otrzymujemy z&nbsp;twierdzenia N7
  
:::<math>\quad \: = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} - \alpha \beta \cdot {\small\frac{\alpha^{m - 1} - \beta^{m - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
+
::<math>2^p U_{p + 1} = (p + 1) P^p + \binom{p + 1}{3} P^{p - 2} D + \binom{p + 1}{5} P^{p - 4} D^2 + \ldots + \binom{p + 1}{p - 2} P^3 D^{(p - 3) / 2} + (p + 1) P D^{(p - 1) / 2}</math>
  
:::<math>\quad \: = U_m U_{n + 1} - Q U_{m - 1} U_n</math>
+
Ponieważ dla <math>k \in [2, p - 1]</math> (zobacz N44)
  
 +
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
  
Wzór 2.
+
to modulo <math>p</math> dostajemy
  
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
+
::<math>2 U_{p + 1} \equiv P + P D^{(p - 1) / 2} \pmod{p}</math>
  
:::<math>\quad \;\! = (\alpha^m + \beta^m) (\alpha^n + \beta^n) - \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
 
  
:::<math>\quad \;\! = V_m V_n - Q^n V_{m - n}</math>
+
Z założenia <math>D</math> jest liczbą niekwadratową modulo <math>p</math>, zatem <math>D^{(p - 1) / 2} \equiv - 1 \pmod{p}</math> (zobacz J31). Skąd wynika natychmiast, że
  
 +
::<math>2 U_{p + 1} \equiv 0 \pmod{p}</math>
  
Wzór 3.
+
Czyli <math>p \mid U_{p + 1}</math>.
  
::<math>U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}}</math>
+
'''Punkt 3.'''
  
:::<math>\quad \: = {\small\frac{(\alpha^m - \beta^m) (\alpha^n + \beta^n)}{\alpha - \beta}} - {\small\frac{\alpha^n \beta^n \cdot (\alpha^{m - n} - \beta^{m - n})}{\alpha - \beta}}</math>
+
Dla parzystego <math>n = p - 1</math> otrzymujemy z&nbsp;twierdzenia N7
  
:::<math>\quad \: = U_m V_n - Q^n U_{m - n}</math>
+
::<math>2^{p - 2} U_{p - 1} = (p - 1) P^{p - 2} + \binom{p - 1}{3} P^{p - 4} D + \binom{p - 1}{5} P^{p - 6} D^2 + \ldots + \binom{p - 1}{p - 4} P^3 D^{(p - 5) / 2} + (p - 1) P D^{(p - 3) / 2}</math>
  
 +
Ponieważ dla <math>k \in [0, p - 1]</math> (zobacz N45)
  
Wzór 4.
+
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
  
::<math>V_{m + n} = \alpha^{m + n} + \beta^{m + n}</math>
+
to modulo <math>p</math> mamy
  
:::<math>\quad \;\! = (\alpha - \beta)^2 \cdot {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} + \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n})</math>
+
::<math>2^{p - 2} U_{p - 1} \equiv - (P^{p - 2} + P^{p - 4} D + P^{p - 6} D^2 + \ldots + P D^{(p - 3) / 2}) \pmod{p}</math>
  
:::<math>\quad \;\! = D U_m U_n + Q^n V_{m - n}</math>
+
::::<math>\quad \,\, \equiv - P (P^{p - 3} + P^{p - 5} D + P^{p - 7} D^2 + \ldots + D^{(p - 3) / 2}) \pmod{p}</math>
  
  
Wzór 5.
+
Z założenia <math>D</math> jest liczbą kwadratową modulo <math>p</math> (zobacz J29), zatem istnieje taka liczba <math>R</math>, że
  
::<math>U_m V_n - V_m U_n = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot (\alpha^n + \beta^n) - (\alpha^m + \beta^m) \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}}</math>
+
::<math>D \equiv R^2 \pmod{p}</math>
  
::::::<math>\;\;\: = 2 \cdot \alpha^n \beta^n \cdot {\small\frac{\alpha^{m - n} - \beta^{m - n}}{\alpha - \beta}}</math>
+
Ponieważ
  
::::::<math>\;\;\: = 2 Q^n U_{m - n}</math>
+
:* <math>(D \mid p) = 1</math>, to <math>p \nmid D</math>, zatem <math>p \nmid R</math>
 +
:* z&nbsp;założenia <math>p \nmid Q</math>, to <math>P^2 - R^2 \equiv P^2 - D \equiv 4 Q \not\equiv 0 \pmod{p}</math>
  
  
Wzór 6.
+
Czyli
  
::<math>U^2_n = \left( {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \right)^2</math>
+
::<math>2^{p - 2} U_{p - 1} \equiv - P (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
  
:::<math>\;\! = {\small\frac{\alpha^{n - 1} - \beta^{n - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} + \alpha^{n - 1} \beta^{n - 1}</math>
 
  
:::<math>\;\! = U_{n - 1} U_{n + 1} + Q^{n - 1}</math>
+
Uwzględniając, że <math>P^2 - R^2 \not\equiv 0 \pmod{p}</math>, możemy napisać
  
 +
::<math>2^{p - 2} (P^2 - R^2) U_{p - 1} \equiv - P (P^2 - R^2) (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
  
Wzór 7.
+
::::::::<math>\equiv - P (P^{p - 1} - R^{p - 1}) \pmod{p}</math>
  
::<math>V^2_n = (\alpha^n + \beta^n)^2</math>
+
::::::::<math>\equiv 0 \pmod{p}</math>
  
:::<math>\;\! = (\alpha^{n - 1} + \beta^{n - 1}) (\alpha^{n + 1} + \beta^{n + 1}) - (\alpha - \beta)^2 \cdot \alpha^{n - 1} \beta^{n - 1}</math>
+
Zauważmy, że wynik nie zależy od tego, czy <math>p \mid P</math>, czy <math>p \nmid P</math>. Skąd wynika
  
:::<math>\;\! = V_{n - 1} V_{n + 1} - D Q^{n - 1}</math>
+
::<math>U_{p - 1} \equiv 0 \pmod{p}</math>
  
 +
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
'''Wzory 8. - 18. można łatwo udowodnić, korzystając ze wzorów 1. - 7.'''
 
  
Wzór 8. Policzyć sumę wzoru 3. pomnożonego przez <math>2</math> i&nbsp;wzoru 5.
 
  
Wzór 9. Policzyć sumę wzorów 2. i 4.
+
Aby zapisać punkty 2. i 3. twierdzenia N19 (i tylko te punkty) w&nbsp;zwartej formie, musimy założyć, że <math>\gcd (p, D) = 1</math>. Otrzymujemy<br/>
 +
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N20</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą i <math>\gcd (p, Q D) = 1</math>, to
  
Wzór 10. Połączyć wzory 2. i 4.
+
::<math>U_{p - (D \mid p)} \equiv 0 \pmod{p}</math>
  
Wzór 11. We wzorze 3. położyć <math>m = n</math>.
 
  
Wzór 12. We wzorze 2. położyć <math>m = n</math>.
 
  
Wzór 13. We wzorze 4. położyć <math>m = n</math>.
 
  
Wzór 14. We wzorze 10. położyć <math>m = n</math> lub połączyć wzory 12. i 13.
 
  
Wzór 15. We wzorze 9. położyć <math>m = 1</math>.
+
== Liczby pseudopierwsze Lucasa ==
  
Wzór 16. We wzorze 8. położyć <math>m = 1</math>.
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N21</span><br/>
 +
Z twierdzenia N20 wiemy, że liczby pierwsze nieparzyste <math>p</math> takie, że <math>p \nmid Q D</math> są dzielnikami wyrazów ciągu Lucasa <math>U_{p - (D \mid p)}</math>, gdzie <math>(D \mid p)</math> oznacza symbol Legendre'a. Jeśli zastąpimy symbol Legendre'a symbolem Jacobiego, to będziemy mogli badać prawdziwość tego twierdzenia dla liczb złożonych i&nbsp;łatwo przekonamy się, że dla pewnych liczb złożonych <math>m</math> kongruencja
  
Wzór 17. We wzorze 15. położyć <math>V_{n + 1} = P V_n - Q V_{n - 1}</math>.
+
::<math>U_{m - (D \mid m)} \equiv 0 \pmod{m}</math>
  
Wzór 18. We wzorze 16. położyć <math>U_{n + 1} = P U_n - Q U_{n - 1}</math>.
+
również jest prawdziwa. Prowadzi to definicji liczb pseudopierwszych Lucasa.
  
  
'''Wzory 19. - 21. to wzory, które wykorzystamy w&nbsp;przyszłości do szybkiego obliczania wartości wyrazów <math>U_n</math> i <math>V_n</math> modulo.'''
 
  
Wzór 19. Wystarczy połączyć wzory 11. oraz 16.
+
<span style="font-size: 110%; font-weight: bold;">Definicja N22</span><br/>
 +
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P</math> i <math>Q</math> (symbolicznie: LPSP( <math>P, Q</math> )), jeżeli <math>\gcd (m, Q D) = 1</math> i
  
Wzór 20. Wystarczy we wzorze 1. położyć <math>m = n + 1</math>.
+
::<math>U_{m - (D \mid m)} \equiv 0 \pmod{m}</math>
  
Wzór 21. Kładąc we wzorze 19. <math>n \rightarrow n + 1</math>, otrzymujemy
+
gdzie <math>(D \mid m)</math> oznacza symbol Jacobiego.
  
::<math>U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - P U^2_{n + 1} \qquad (*)</math>
 
  
Kładąc we wzorze 1. <math>m = n + 2</math>, mamy
 
  
::<math>U_{2 n + 2} = U_{n + 2} U_{n + 1} - Q U_{n + 1} U_n</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N23</span><br/>
 +
Jeżeli liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, gdzie <math>a \geqslant 2</math>, to jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>.
  
Czyli
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Połóżmy we wzorze definiującym ciąg Lucasa
  
::<math>2 U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - 2 Q U_n U_{n + 1}</math>
+
::<math>U_m = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}}</math>
  
Odejmując od powyższego wzoru wzór <math>(*)</math>, dostajemy wzór 21.
+
<math>\alpha = a</math> i <math>\beta = 1</math>. Odpowiada to parametrom <math>P = \alpha + \beta = a + 1</math>, <math>Q = \alpha \beta = a</math>, <math>D = (\alpha - \beta)^2 = (a - 1)^2</math>.
  
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
+
Ponieważ musi być <math>\gcd (m, Q D) = 1</math>, to mamy <math>\gcd (m, (a - 1) a) = 1</math> i&nbsp;wynika stąd, że <math>(D \mid m) = 1</math>. Z&nbsp;założenia <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, zatem
  
Co należało pokazać.<br/>
+
::<math>U_{m - 1} (a + 1, a) \equiv 0 \pmod{m}</math>
&#9633;
 
{{\Spoiler}}
 
  
 +
Czyli
  
 +
::<math>{\small\frac{a^{m - 1} - 1}{a - 1}} \equiv 0 \pmod{m}</math>
  
 +
Jeżeli <math>m \biggr\rvert {\small\frac{a^{m - 1} - 1}{a - 1}}</math>, to tym bardziej <math>m \big\rvert (a^{m - 1} - 1)</math> i&nbsp;możemy napisać
  
 +
::<math>a^{m - 1} - 1 \equiv 0 \pmod{m}</math>
  
== Obliczanie wyrazów ciągu Lucasa modulo <math>m</math> ==
+
Zatem <math>m</math> jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>. Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
<span style="font-size: 110%; font-weight: bold;">Przykład L29</span><br/>
 
Pokażemy, jak wykorzystać podane w&nbsp;twierdzeniu L28 wzory 19, 20, 21 i 16
 
  
::<math>U_{2 n} = 2 U_n U_{n + 1} - P U^2_n</math>
 
  
::<math>U_{2 n + 1} = U^2_{n + 1} - Q U^2_n</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N24</span><br/>
 +
Wykorzystując funkcje <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz J48, N15) możemy napisać prosty program, który sprawdza, czy dla liczby nieparzystej <math>m</math> prawdziwe jest twierdzenie N20.
  
::<math>U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1}</math>
+
<span style="font-size: 90%; color:black;">isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q) =
 
+
{
::<math>V_n = 2 U_{n + 1} - P U_n</math>
+
'''local'''(D, js);
 +
D = P^2 - 4*Q;
 +
'''if'''( gcd(m, 2*Q*D) > 1, '''return'''(0) );
 +
js = jacobi(D, m);
 +
'''if'''( modLucas(m - js, P, Q, m)[1] == 0, '''return'''(1), '''return'''(0) );
 +
}
  
do szybkiego obliczania wyrazów ciągu Lucasa modulo <math>m</math>.
 
  
  
Niech <math>P = 3</math>, <math>Q = 1</math>, <math>D = P^2 - 4 Q = 5</math>, <math>n = 22 = (10110)_2 = \sum_{j = 0}^{4} a_j \cdot 2^j</math>.
+
<span style="font-size: 110%; font-weight: bold;">Przykład N25</span><br/>
 +
Poniższa tabela zawiera najmniejsze liczby pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
  
W tabeli przedstawione są kolejne kroki, jakie musimy wykonać, aby policzyć <math>U_n = U_{22}</math> modulo <math>m = 23</math>.
+
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 
+
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
+
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
 
|-
 
|-
! <math>\boldsymbol{j}</math> !! <math>\boldsymbol{a_j}</math> !! <math>\boldsymbol{k_j}</math> !! <math>\boldsymbol{U_{k_j}}</math> !! <math>\boldsymbol{U_{k_j + 1}}</math>
+
! <math>\boldsymbol{- 5}</math>
 +
| <math>253</math> || <math>121</math> || <math>57</math> || <math>217</math> || style="background-color: yellow" | <math>323</math> || <math>69</math> || <math>121</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>  
 
|-
 
|-
| <math>4</math> || <math>1</math> || <math>(1)_2 = 1</math> || <math>U_1 = 1</math> || <math>U_2 = P = 3</math>
+
! <math>\boldsymbol{- 4}</math>
 +
| <math>9</math> || style="background-color: yellow" | <math>323</math> || <math>91</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 
|-
 
|-
| <math>3</math> || <math>0</math> || <math>(10)_2 = 2</math> || <math>U_2 = 2 U_1 U_2 - 3 U^2_1 = 6 - 3 = 3</math> || <math>U_3 = U^2_2 - 1 = 8</math>
+
! <math>\boldsymbol{- 3}</math>
 +
| <math>217</math> || <math>91</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math>  
 
|-
 
|-
| <math>2</math> || <math>1</math> || <math>(101)_2 = 5</math> || <math>U_5 = U^2_3 - U^2_2 = 64 - 9 = 55 \equiv 9</math> || <math>U_6 = 3 U_3^2 - 2 U_2 U_3 = 192 - 48 = 144 \equiv 6</math>
+
! <math>\boldsymbol{- 2}</math>
 +
| <math>341</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>39</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>85</math>  
 
|-
 
|-
| <math>1</math> || <math>1</math> || <math>(1011)_2 = 11</math> || <math>U_{11} = U^2_6 - U^2_5 \equiv 36 - 81 \equiv - 45 \equiv 1</math> || <math>U_{12} = 3 U_6^2 - 2 U_5 U_6 \equiv 108 - 108 \equiv 0</math>
+
! <math>\boldsymbol{- 1}</math>
 +
| style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>15</math>
 +
|-
 +
! <math>\boldsymbol{1}</math>
 +
| <math>25</math> || style="background-color: red" | <math></math> || <math>21</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>115</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>
 +
|-
 +
! <math>\boldsymbol{2}</math>
 +
| <math>1541</math> || <math>9</math> || <math>341</math> || style="background-color: yellow" | <math>35</math> || <math>21</math> || <math>85</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>  
 
|-
 
|-
| <math>0</math> || <math>0</math> || <math>(10110)_2 = 22</math> || <math>U_{22} = 2 U_{11} U_{12} - 3 U^2_{11} \equiv 0 - 3 \equiv 20</math> || <math>U_{23} = U^2_{12} - U^2_{11} \equiv 0 - 1 \equiv 22</math>
+
! <math>\boldsymbol{3}</math>
 +
| style="background-color: yellow" | <math>629</math> || style="background-color: yellow" | <math>559</math> || <math>25</math> || <math>91</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>
 +
|-
 +
! <math>\boldsymbol{4}</math>
 +
| style="background-color: yellow" | <math>119</math> || <math>25</math> || style="background-color: yellow" | <math>209</math> || style="background-color: red" | <math></math> || <math>85</math> || <math>21</math> || style="background-color: yellow" | <math>119</math> || style="background-color: yellow" | <math>65</math> || <math>9</math> || style="background-color: yellow" | <math>115</math>
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>49</math> || style="background-color: yellow" | <math>143</math> || style="background-color: yellow" | <math>323</math> || <math>217</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 
|}
 
|}
  
W kolumnie <math>a_j</math> wypisujemy kolejne cyfry liczby <math>n = 22 = (10110)_2</math> zapisanej w&nbsp;układzie dwójkowym. Liczby w&nbsp;kolumnie <math>k_j</math> tworzymy, biorąc kolejne (od prawej do lewej) cyfry liczby <math>n</math> w&nbsp;zapisie dwójkowym. Postępując w&nbsp;ten sposób, w&nbsp;ostatnim wierszu mamy <math>k_j = n</math> i&nbsp;wyliczamy liczby <math>U_n</math> i <math>U_{n + 1}</math> modulo <math>m</math>.
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
+
<span style="font-size: 90%; color:black;">FirstLPSP(Stop) =
Dla uproszczenia zapisu i&nbsp;ułatwienia zrozumienia liczbę <math>k_j</math> oznaczymy jako <math>r</math>, a <math>k_{j + 1}</math> jako <math>s</math>. Zauważmy, że
+
\\ najmniejsze LPSP(P,Q) < Stop; dla 1<=P<=10 i -5<=Q<=5
 
+
{
:* tabela jest zbudowana tak, że musimy znaleźć wyrazy ciągu Lucasa o&nbsp;indeksie <math>r = k_j</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>r + 1 = k_j + 1</math>
+
'''local'''(D, m, P, Q);
:* przejście do następnego wiersza (w dół) oznacza, że musimy znaleźć wyrazy o&nbsp;indeksie <math>s = k_{j + 1}</math> oraz o&nbsp;indeksie o&nbsp;jeden większym: <math>s + 1</math>
+
Q = -6;
:* przechodząc do następnego wiersza, dotychczasowa liczba <math>r = k_j</math> powiększa się o&nbsp;kolejną cyfrę ( <math>0</math> lub <math>1</math> ), którą dopisujemy z&nbsp;prawej strony
+
'''while'''( Q++ <= 5,
:* dodanie na końcu liczby <math>r = k_j</math> zera podwaja liczbę <math>r</math>, czyli <math>s = k_{j + 1} = 2 r</math> oraz <math>s + 1 = 2 r + 1</math>
+
        '''if'''( Q == 0, '''next'''() );
:* dodanie na końcu liczby <math>r = k_j</math> jedynki podwaja liczbę <math>r</math> i&nbsp;zwiększą ją o&nbsp;jeden, czyli <math>s = k_{j + 1} = 2 r + 1</math> oraz <math>s + 1 = 2 r + 2</math>
+
        P = 0;
 +
        '''while'''( P++ <= 10,
 +
              D = P^2 - 4*Q;
 +
              '''if'''( D == 0,
 +
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
 +
                  '''next'''();
 +
                );
 +
              m = 3;
 +
              '''while'''( m < Stop,
 +
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q)  &&  !'''isprime'''(m),
 +
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 +
                          '''break'''();
 +
                        );
 +
                      m = m + 2;
 +
                    );
 +
            );
 +
      );
 +
}</span>
 +
<br/>
 +
{{\Spoiler}}
  
 +
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \mid m) = - 1</math>.
  
Dlatego, jeżeli kolejną dodaną cyfrą jest zero, to korzystamy ze wzorów
 
  
::<math>U_s = U_{2 r} = 2 U_r U_{r + 1} - P U^2_r</math>
 
 
::<math>U_{s + 1} = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r</math>
 
 
Gdy kolejną dodaną cyfrą jest jeden, to stosujemy wzory
 
 
::<math>U_s = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r</math>
 
 
::<math>U_{s + 1} = U_{2 r + 2} = P U^2_{r + 1} - 2 Q U_r U_{r + 1}</math>
 
 
 
Korzystając ze wzoru <math>V_n = 2 U_{n + 1} - P U_n</math>, mamy
 
 
::<math>V_{22} = 2 U_{23} - 3 U_{22} \equiv 44 - 60 \equiv - 16 \equiv 7 \pmod{23}</math>
 
 
Ostatecznie otrzymujemy
 
 
::<math>U_{22} \equiv 20 \pmod{23} \quad</math> oraz <math>\quad V_{22} \equiv 7 \pmod{23}</math>
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Przykład N26</span><br/>
 +
Ilość liczb LPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
  
 +
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 +
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 +
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
 +
|-
 +
! <math>\boldsymbol{- 5}</math>
 +
| <math>4266</math> || <math>4935</math> || <math>4278</math> || <math>4981</math> || <math>6363</math> || <math>6028</math> || <math>5202</math> || <math>4426</math> || <math>5832</math> || <math>6027</math>
 +
|-
 +
! <math>\boldsymbol{- 4}</math>
 +
| <math>4599</math> || <math>4152</math> || <math>9272</math> || <math>5886</math> || <math>6958</math> || <math>4563</math> || <math>5600</math> || <math>9509</math> || <math>7007</math> || <math>4142</math>
 +
|-
 +
! <math>\boldsymbol{- 3}</math>
 +
| <math>4265</math> || <math>5767</math> || <math>4241</math> || <math>5114</math> || <math>5859</math> || <math>7669</math> || <math>6083</math> || <math>6120</math> || <math>4420</math> || <math>5096</math>
 +
|-
 +
! <math>\boldsymbol{- 2}</math>
 +
| <math>5361</math> || <math>4389</math> || <math>5063</math> || <math>5632</math> || <math>5364</math> || <math>5228</math> || <math>5859</math> || <math>10487</math> || <math>5370</math> || <math>9798</math>
 +
|-
 +
! <math>\boldsymbol{- 1}</math>
 +
| <math>4152</math> || <math>5886</math> || <math>4563</math> || <math>9509</math> || <math>4142</math> || <math>6273</math> || <math>5773</math> || <math>4497</math> || <math>5166</math> || <math>5305</math>
 +
|-
 +
! <math>\boldsymbol{1}</math>
 +
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>6567</math> || <math>7669</math> || <math>7131</math> || <math>10882</math> || <math>8626</math> || <math>8974</math> || <math>8509</math> || <math>8752</math>
 +
|-
 +
! <math>\boldsymbol{2}</math>
 +
| <math>7803</math> || <math>449152466</math> || <math>5597</math> || <math>5886</math> || <math>6509</math> || <math>5761</math> || <math>8115</math> || <math>6945</math> || <math>8380</math> || <math>7095</math>
 +
|-
 +
! <math>\boldsymbol{3}</math>
 +
| <math>5974</math> || <math>8768</math> || <math>282485800</math> || <math>5767</math> || <math>5651</math> || <math>5632</math> || <math>6640</math> || <math>5725</math> || <math>6058</math> || <math>7050</math>
 +
|-
 +
! <math>\boldsymbol{4}</math>
 +
| <math>10749</math> || <math>282485800</math> || <math>14425</math> || style="background-color: red" | <math></math> || <math>9735</math> || <math>6567</math> || <math>8164</math> || <math>7669</math> || <math>7608</math> || <math>7131</math>
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>5047</math> || <math>15127</math> || <math>6155</math> || <math>15127</math> || <math>4152</math> || <math>5146</math> || <math>4423</math> || <math>5526</math> || <math>6289</math> || <math>9509</math>
 +
|}
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L30</span><br/>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
Uogólniając postępowanie przedstawione w&nbsp;przykładzie L29, możemy napisać program w&nbsp;PARI/GP do szybkiego obliczania wyrazów ciągu Lucasa <math>U_n (P, Q)</math> i <math>V_n (P, Q)</math> modulo <math>m</math>.
+
  <span style="font-size: 90%; color:black;">NumOfLPSP(Stop) =
 
+
\\ ilość liczb pseudopierwszych Lucasa LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
  <span style="font-size: 90%; color:black;">modLucas(n, P, Q, m) =
 
 
  {
 
  {
  '''local'''(A, i, s, U, U2, V, W, W2);
+
  '''local'''(D, m, P, Q);
  '''if'''( m == 1, '''return'''([0, 0]) );
+
Q = -6;
'''if'''( n == 0, '''return'''([0, 2 % m]) );
+
  '''while'''( Q++ <= 5,
A = '''digits'''(n, 2); \\ otrzymujemy wektor cyfr liczby n w układzie dwójkowym
+
        '''if'''( Q == 0, '''next'''() );
s = '''length'''(A); \\ długość wektora A
+
        P = 0;
U = 1;
+
        '''while'''( P++ <= 10,
W = P;
+
              D = P^2 - 4*Q;
i = 1;
+
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
'''while'''( i++ <= s,
+
              s = 0;
        '''if'''( A[i] == 0U2 = 2*U*W - P*U^2; W2 = W^2 - Q*U^2 );
+
              m = 3;
        '''if'''( A[i] == 1, U2 = W^2 - Q*U^2;  W2 = P*W^2 - 2*Q*U*W );
+
              '''while'''( m < Stop,
        U = U2 % m;
+
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q)  && !'''isprime'''(m), s++ );
        W = W2 % m;
+
                      m = m + 2;
 +
                    );
 +
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
 +
            );
 
       );
 
       );
V = (2*W - P*U) % m;
 
'''return'''([U, V]);
 
 
  }</span>
 
  }</span>
 +
<br/>
 +
{{\Spoiler}}
  
  
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga N27</span><br/>
 +
Dla <math>(P, Q) = (1, 1)</math> ciąg Lucasa <math>(U_n)</math> ma postać
  
 +
::<math>(U_n) = (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, \ldots)</math>
  
== Podzielność wyrazów <math>U_n (P, Q)</math> przez liczbę pierwszą nieparzystą ==
+
Stosując indukcję matematyczną, udowodnimy, że <math>U_{3 k} = 0</math>. Łatwo sprawdzamy, że dla <math>k = 0</math> i <math>k = 1</math> wzór jest prawdziwy. Zakładając prawdziwość wzoru dla wszystkich liczb naturalnych nie większych od <math>k</math>, otrzymujemy dla <math>k + 1</math> (zobacz N13 p.3)
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L31</span><br/>
+
::<math>U_{3 (k + 1)} = U_{3 k + 3} = U_{3 k} V_3 - U_{3 (k - 1)} = 0</math>
Niech <math>p</math> będzie liczbą pierwszą nieparzystą. W&nbsp;przypadku, gdy <math>p \nmid P Q</math> nie możemy nic powiedzieć o&nbsp;podzielności wyrazów <math>U_n</math> przez <math>p</math>. Przykładowo, jeżeli <math>P \equiv 1 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math>, mamy
 
  
::<math>(U_n) \equiv (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, \ldots)</math>
+
Co kończy dowód. Zbadajmy liczby pseudopierwsze Lucasa dla <math>(P, Q) = (1, 1)</math>.
  
W przypadku, gdy <math>P \equiv 2 \pmod{p} \;</math> <math>\text{i} \;\; Q \equiv 1 \pmod{p}</math>, to modulo <math>p</math> mamy
+
Mamy <math>D = P^2 - 4 Q = - 3</math>. Wynika stąd, że nie może być <math>3 \mid m</math>, bo mielibyśmy <math>\gcd (m, Q D) = 3 > 1</math>.
  
::<math>(U_n) \equiv (0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, \ldots)</math>
+
Z zadania J46 wiemy, że
  
Sytuacja wygląda inaczej, gdy <math>p \, | \, P Q</math>.
+
::<math>(- 3 \mid m) =
 +
\begin{cases}
 +
\;\;\: 1 & \text{gdy } m = 6 k + 1 \\
 +
\;\;\: 0 & \text{gdy } m = 6 k + 3 \\
 +
      - 1 & \text{gdy } m = 6 k + 5 \\
 +
\end{cases}</math>
  
 +
Ponieważ <math>3 \nmid m</math>, to wystarczy zbadać przypadki <math>m = 6 k + 1</math> i <math>m = 6 k + 5</math>. W&nbsp;pierwszym przypadku jest
  
 +
::<math>U_{m - (- 3 \mid m)} = U_{6 k + 1 - 1} = U_{6 k} = 0</math>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L32</span><br/>
+
W drugim przypadku, gdy <math>m = 6 k + 5</math>, dostajemy
Niech <math>p</math> będzie liczbą pierwszą nieparzystą.
 
  
::{| border="0"
+
::<math>U_{m - (- 3 \mid m)} = U_{6 k + 5 + 1} = U_{6 (k + 1)} = 0</math>
|-style=height:1.9em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, P \;</math> <math>\text{i} \;\; p \, | \, Q , \;</math> to <math>\; p \, | \, U_n \;</math> dla <math>n \geqslant 2</math>
 
|-style=height:1.9em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, P \;</math> <math>\text{i} \;\; p \nmid Q , \;</math> to <math>\; p \, | \, U_{2 n} \;</math> i <math>\; p \nmid U_{2 n + 1}</math>
 
|-style=height:1.9em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \, | \, Q , \;</math> to <math>\; p \nmid U_n \;</math> dla <math>n \geqslant 1</math>
 
|-style=height:1.9em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \, | \, Q , \;</math> to <math>\; p \, | \, U_n</math>, gdzie <math>n \geqslant 2</math>, wtedy i&nbsp;tylko wtedy, gdy <math>\; p \, | \, P</math>
 
|-style=height:1.9em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>\; p \nmid P \;</math> <math>\text{i} \;\; p \, | \, D , \;</math> to <math>\; p \, | \, U_n \;</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \, | \, n</math>
 
|}
 
  
Założenie, że <math>p \nmid P</math> w&nbsp;ostatnim punkcie jest istotne. Gdy <math>\; p \, | \, P \;</math> i <math>\; p \, | \, D , \;</math> to <math>\; p \, | \, Q \;</math> i&nbsp;otrzymujemy punkt pierwszy.
+
Zatem dla dowolnej liczby nieparzystej <math>m</math> niepodzielnej przez <math>3</math> jest
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
::<math>U_{m - (- 3 \mid m)} \equiv 0 \pmod{m}</math>
'''Punkt 1.'''
 
  
Ponieważ <math>U_2 = P</math>, zatem <math>p \, | \, U_2</math>. Dla <math>n \geqslant 3</math> wyrażenie <math>U_n = P U_{n - 1} - Q U_{n - 2}</math> jest podzielne przez <math>p</math>.
+
Czyli liczbami pseudopierwszymi Lucasa dla parametrów <math>(P, Q) = (1, 1)</math> będą liczby nieparzyste <math>m</math>, które nie są podzielne przez <math>3</math> i&nbsp;nie są liczbami pierwszymi. Ilość takich liczb nie większych od <math>10^k</math> możemy łatwo znaleźć poleceniem
  
'''Punkt 2.'''
+
<span style="font-size: 90%; color:black;">'''for'''(k = 1, 9, s = 0; '''forstep'''(m = 3, 10^k, 2, '''if'''( m%6 <> 3, s = s + !'''isprime'''(m) )); '''print'''(s))</span>
  
Indeksy parzyste. Indukcja matematyczna. Mamy <math>U_0 = 0</math> i <math>U_2 = P</math>, zatem <math>p \, | \, U_0</math> i <math>p \, | \, U_2</math>. Zakładając, że <math>p \, | \, U_{2 n}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 2}</math>
 
  
::<math>U_{2 n + 2} = P U_{2 n - 1} - Q U_{2 n}</math>
 
  
Z założenia indukcyjnego wynika, że <math>p \, | \, U_{2 n + 2}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 0</math>.
+
<span style="font-size: 110%; font-weight: bold;">Zadanie N28</span><br/>
 +
Pokazać, że ilość liczb pseudopierwszych Lucasa dla parametrów <math>(P, Q) = (2, 2)</math> nie większych od <math>10^k</math> możemy znaleźć poleceniem
  
Indeksy nieparzyste. Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_3 = P^2 - Q</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_3</math>. Zakładając, że <math>p \nmid U_{2 n - 1}</math>, z definicji ciągu <math>(U_k)</math>, otrzymujemy dla <math>U_{2 n + 1}</math>
+
<span style="font-size: 90%; color:black;">'''for'''(k = 1, 9, s = 0; '''forstep'''(m = 3, 10^k, 2, s = s + !'''isprime'''(m)); '''print'''(s))</span>
  
::<math>U_{2 n + 1} = P U_{2 n} - Q U_{2 n - 1}</math>
 
  
Z założenia indukcyjnego wynika, że <math>p \nmid U_{2 n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich <math>n \geqslant 1</math>.
 
  
'''Punkt 3.'''
 
  
Indukcja matematyczna. Mamy <math>U_1 = 1</math> i <math>U_2 = P</math>, zatem <math>p \nmid U_1</math> i <math>p \nmid U_2</math>. Zakładając, że <math>p \nmid U_n</math> zachodzi dla wszystkich liczb całkowitych dodatnich nie większych od <math>n</math>, z&nbsp;definicji ciągu <math>(U_n)</math>
 
otrzymujemy dla <math>n + 1</math>
 
  
::<math>U_{n + 1} = P U_n - Q U_{n - 1}</math>
+
== Metoda Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math> ==
  
Z założenia indukcyjnego wynika, że <math>p \nmid U_{n + 1}</math>, zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich liczb <math>n \geqslant 1</math>.
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N29</span><br/>
 +
Twierdzenie N20 możemy wykorzystać do testowania pierwszości liczb. Ponieważ musi być spełniony warunek <math>\gcd (m, Q D) = 1</math>, to nie każda para liczb <math>P, Q</math> (np. wybrana losowo) nadaje się do przeprowadzenia testu. Zawsze będziemy zmuszeni określić zasadę postępowania, która doprowadzi do wyboru właściwej pary <math>P, Q</math>.
  
'''Punkt 4.'''
+
Robert Baillie i&nbsp;Samuel Wagstaff przedstawili<ref name="BaillieWagstaff1"/> dwie metody wyboru parametrów dla testu Lucasa. Ograniczymy się do omówienia tylko pierwszej z&nbsp;nich (metodę zaproponował John Selfridge).
  
Wynika z&nbsp;punktów pierwszego i&nbsp;trzeciego.
+
Rozważmy ciąg <math>a_k = (- 1)^k (2 k + 1)</math>, gdzie <math>k \geqslant 2</math>, czyli <math>a_k = (5, - 7, 9, - 11, 13, - 15, \ldots)</math>. Niech <math>D</math> będzie pierwszym wyrazem ciągu <math>(a_k)</math>, dla którego jest <math>(a_k \mid m) = - 1</math>. Dla tak ustalonego <math>D</math> przyjmujemy <math>P = 1</math> i <math>Q = (1 - D) / 4</math>.
  
'''Punkt 5.'''
+
Tabela przedstawia początkowe wartości <math>Q</math>, jakie otrzymamy, stosując tę metodę.
  
Z twierdzenia L22 wiemy, że
+
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 +
! <math>\boldsymbol{k}</math>
 +
| <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
 +
|-
 +
!  <math>\boldsymbol{a_k}</math>
 +
| <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
 +
|-
 +
!  <math>\boldsymbol{Q}</math>
 +
| <math>-1</math> || <math>2</math> || style="background-color: red" | <math>-2</math> || <math>3</math> || <math>-3</math> || <math>4</math> || <math>-4</math> || <math>5</math> || <math>-5</math> || <math>6</math> || style="background-color: red" | <math>-6</math> || <math>7</math> || <math>-7</math> || <math>8</math> || <math>-8</math> || <math>9</math> || <math>-9</math> || <math>10</math> || <math>-10</math>
 +
|}
  
::<math>2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k</math>
 
  
::::<math>\;\; = n P^{n - 1} + \binom{n}{3} P^{n - 3} D + \binom{n}{5} P^{n - 5} D^2 + \ldots +
+
Zauważmy, że
\begin{cases}
+
:* jeżeli liczba nieparzysta <math>m</math> jest liczbą kwadratową, to wybór <math>D</math> nie będzie możliwy
n P D^{(n - 2) / 2} & \text{gdy }n\text{ jest parzyste} \\
+
:* w&nbsp;przypadku zastosowania tej metody znajdziemy tylko liczby pierwsze lub pseudopierwsze Lucasa, które spełniają kongruencję <math>U_{m + 1} \equiv 0 \pmod{m}</math>, czyli tylko część liczb pseudopierwszych Lucasa określonych w&nbsp;definicji N22
D^{(n - 1) / 2} & \text{gdy }n\text{ jest nieparzyste}
 
\end{cases}</math>
 
  
Z założenia <math>p \, | \, D</math>, zatem modulo <math>p</math> dostajemy
 
  
::<math>2^{n - 1} U_n \equiv n P^{n - 1} \pmod{p}</math>
+
Ponieważ Baillie i&nbsp;Wagstaff określili metodę zaproponowaną przez Selfridge'a jako metodę A, to pozostaniemy przy tej nazwie. Korzystając ze wzoru rekurencyjnego
  
Ponieważ <math>p \nmid P</math>, zatem <math>p \, | \, U_n</math> wtedy i&nbsp;tylko wtedy, gdy <math>p \, | \, n</math>.
+
::<math> a_{k+1} =
Co należało pokazać.<br/>
+
  \begin{cases}
&#9633;
+
  \qquad \qquad 5 & \text{gdy } k = 1 \\
{{\Spoiler}}
+
      - a_k - 2 * \mathop{\textnormal{sign}}( a_k ) & \text{gdy } k \geqslant 2 \\
 +
  \end{cases}</math>
  
 +
możemy łatwo napisać odpowiednią funkcję znajdującą liczby <math>P, Q</math> według tej metody.
  
 +
<span style="font-size: 90%; color:black;">MethodA(m) =
 +
{
 +
'''local'''(a, js);
 +
a = 5;
 +
'''while'''( 1,
 +
        js = jacobi(a, m);
 +
        '''if'''( js == 0  &&  a % m <> 0, '''return'''([0, 0]) );
 +
        '''if'''( js == -1, '''return'''([1, (1 - a)/4]) );
 +
        a = -a - 2*'''sign'''(a);
 +
      );
 +
}</span>
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L33</span><br/>
+
Wyjaśnienia wymaga druga linia kodu w&nbsp;pętli <code>while</code>. Wiemy, że (zobacz J42)
Jeżeli <math>d</math> jest nieparzystym dzielnikiem <math>Q</math>, to dla <math>n \geqslant 2</math> jest
 
  
::<math>U_n \equiv P^{n - 1} \pmod{d}</math>
+
::<math>(a \mid m) = 0 \quad \qquad \Longleftrightarrow \quad \qquad \gcd (a, m) > 1</math>
  
W szczególności, gdy liczba pierwsza nieparzysta <math>p</math> jest dzielnikiem <math>Q</math> i <math>p \nmid P</math>, to
+
Jednak z&nbsp;faktu, że <math>\gcd (a, m) > 1</math> nie wynika natychmiast, że liczba <math>m</math> jest liczbą złożoną. Rozważmy dwa przypadki: gdy <math>m \mid a</math> i <math>m \nmid a</math>.
  
::<math>U_p \equiv 1 \pmod{p}</math>
+
Gdy <math>\gcd (a, m) > 1</math> i <math>m \mid a</math>, to <math>\gcd (a, m) = \gcd (k \cdot m, m) = m > 1</math> i&nbsp;nie jesteśmy w&nbsp;stanie rozstrzygnąć, czy liczba <math>m</math> jest liczbą pierwszą, czy złożoną. Widać to dobrze na prostych przykładach
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
::<math>\gcd (7, 7) = \gcd (14, 7) = 7 > 1</math>
Oznaczmy <math>\delta = \sqrt{D}</math>, zatem <math>2 \alpha = P + \delta</math> i <math>2 \beta = P - \delta</math>. Ze wzoru dwumianowego, mamy
 
  
::<math>2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j</math>
+
::<math>\gcd (15, 15) = \gcd (30, 15) = 15 > 1</math>
  
::<math>2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j</math>
+
Gdy <math>\gcd (a, m) > 1</math> i <math>m \nmid a</math>, to <math>m</math> jest liczbą złożoną. Ponieważ <math>m \nmid a</math>, to <math>a = k \cdot m + r</math>, gdzie <math>r \in [1, m - 1]</math>. Mamy
  
 +
::<math>\gcd (a, m) = \gcd (k \cdot m + r, m) = \gcd (r, m) = d</math>
  
Obliczając różnicę wyjściowych wzorów, mamy
+
Musi być <math>d > 1</math>, bo założyliśmy, że <math>\gcd (a, m) > 1</math> i&nbsp;musi być <math>d < m</math>, bo <math>d \leqslant r \leqslant m - 1</math>. Zatem <math>d</math> jest dzielnikiem nietrywialnym liczby <math>m</math> i <math>m</math> jest liczbą złożoną.
  
::<math>2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) =</math>
+
Omawiana linia kodu zapewnia wysłanie informacji o&nbsp;tym, że liczba <math>m</math> jest liczbą złożoną (zwrot wektora [0, 0]). W&nbsp;przypadku, gdy nie mamy takiej pewności, kontynuujemy szukanie liczby <math>a</math>, takiej że <math>(a \mid m) = - 1</math>, pozostawiając zbadanie pierwszości liczby <math>m</math> na kolejnym etapie testowania.
  
:::::<math>\quad \: = \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot 2 \delta^j</math>
 
  
:::::<math>\quad \: = 2 \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot \delta \cdot D^{(j - 1) / 2}</math>
+
Uważny Czytelnik dostrzeże, że nie zbadaliśmy, czy spełniony jest warunek <math>\gcd (m, Q) = 1</math>. Nie musimy tego robić, bo zwracana przez funkcję <code>MethodA()</code> liczba <math>Q</math> jest względnie pierwsza z <math>m</math>. Omówimy ten problem dokładnie w&nbsp;zadaniu N30. Poniżej pokażemy, że nawet gdyby było <math>\gcd (m, Q) > 1</math>, to złożona liczba <math>m</math> nie zostanie uznana za liczbę pseudopierwszą Lucasa.
  
Rozpatrując powyższą równość modulo <math>Q</math> dostajemy (zobacz L58)
+
Zauważmy, że jeżeli <math>m</math> jest liczbą złożoną i&nbsp;ma dzielnik pierwszy <math>p < m</math>, który dzieli <math>Q</math>, to <math>p \mid Q</math> i <math>p \nmid P</math> (bo <math>P = 1</math>), zatem <math>p \nmid U_k</math> dla <math>k \geqslant 1</math> (zobacz N17), czyli nie może być
  
::<math>2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\delta}} = 2^{n - 1} U_n \equiv \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot P^{j - 1}</math>
+
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{m}</math>
  
:::::::::<math>\;\:\: \equiv P^{n - 1} \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j}</math>
+
bo mielibyśmy
  
:::::::::<math>\;\:\: \equiv 2^{n - 1} P^{n - 1}</math>
+
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{p}</math>
  
Czyli
+
a to jest niemożliwe. Zatem program wykorzystujący twierdzenie N20 wykryje złożoność liczby <math>m</math>.
  
::<math>2^{n - 1} (U_n - P^{n - 1}) \equiv 0 \pmod{Q}</math>
+
Łatwo pokażemy, że nie jest możliwe, aby liczba <math>m</math> była liczbą pierwszą i&nbsp;była dzielnikiem <math>Q</math>. Jeżeli <math>m</math> jest liczbą pierwszą, to istnieje dokładnie <math>\tfrac{m - 1}{2}</math> liczb kwadratowych modulo <math>p</math> i <math>\tfrac{m - 1}{2}</math> liczb niekwadratowych modulo <math>p</math>, zatem rozpoczynając od wyrazu <math>a_2</math> możemy dojść co najwyżej do wyrazu o&nbsp;indeksie <math>k = \tfrac{m - 1}{2} + 2</math>, czyli
  
Ponieważ <math>Q</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>, to tym bardziej <math>d</math> dzieli <math>2^{n - 1} (U_n - P^{n - 1})</math>. Z założenia <math>\gcd (d, 2^{n - 1}) = 1</math>, zatem <math>d</math> dzieli <math>U_n - P^{n - 1}</math> (zobacz C70).
+
::<math>| a_k | \leqslant m + 4</math>
  
W przypadku szczególnym, gdy <math>d = p</math>, gdzie <math>p</math> jest nieparzystą liczbą pierwszą i <math>p \nmid P</math>, z&nbsp;twierdzenia Fermata otrzymujemy natychmiast
+
Skąd wynika, że
  
::<math>U_p \equiv P^{p - 1} \equiv 1 \pmod{p}</math>
+
::<math>| Q | = \left| {\small\frac{1 - a_k}{4}} \right| \leqslant {\small\frac{m + 5}{4}} < m</math>
  
Co należało pokazać.<br/>
+
Ostatnia nierówność jest prawdziwa dla <math>m > {\small\frac{5}{3}}</math>, czyli dla wszystkich liczb pierwszych. Ponieważ <math>| Q | < m</math>, w&nbsp;przypadku gdy <math>m</math> jest liczbą pierwszą, to <math>m</math> nie może być dzielnikiem liczby <math>Q</math>.
&#9633;
 
{{\Spoiler}}
 
  
  
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L34</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Zadanie N30</span><br/>
Niech <math>D = P^2 - 4 Q</math>, a <math>(D \, | \, p)</math> oznacza symbol Legendre'a, gdzie <math>p</math> jest liczbą pierwszą nieparzystą i <math>p \nmid Q</math>. Mamy
+
Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \mid m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
  
::{| border="0"
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
|-style=height:2em
+
Niech <math>m = 21</math>. Rozpoczniemy od przykładu liczb <math>a_k = (- 1)^k (2 k + 1)</math> dla <math>k = 0, 1, \ldots, m - 1</math>.
| &#9679;&nbsp;&nbsp;&nbsp; <math>U_p \equiv (D \, | \, p) \pmod{p}</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \, | \, p) = - 1 , \;</math> to <math>\; p \, | \, U_{p + 1}</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; jeżeli <math>(D \, | \, p) = 1 , \;</math> to <math>\; p \, | \, U_{p - 1}</math>
 
|}
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: center; margin-right: auto;"
'''Punkt 1.'''
+
! <math>\boldsymbol{k}</math> !! <math>\boldsymbol{0}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{(m-1)/2}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{m-1}</math>
 +
|-
 +
! <math>\boldsymbol{k}</math>
 +
| <math>0</math> || <math>1</math> || <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
 +
|-
 +
! <math>\boldsymbol{a_k}</math>
 +
| <math>1</math> || <math>-3</math> || <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
 +
|-
 +
! <math>\boldsymbol{R_m(a_k)}</math>
 +
| <math>1</math> || <math>18</math> || <math>5</math> || <math>14</math> || <math>9</math> || <math>10</math> || <math>13</math> || <math>6</math> || <math>17</math> || <math>2</math> || <math>0</math> || <math>19</math> || <math>4</math> || <math>15</math> || <math>8</math> || <math>11</math> || <math>12</math> || <math>7</math> || <math>16</math> || <math>3</math> || <math>20</math>
 +
|}
  
Zauważmy, że przypadek gdy <math>p \, | \, Q</math>, omówiliśmy w&nbsp;twierdzeniu poprzednim. Z&nbsp;założenia <math>p</math> jest liczbą pierwszą nieparzystą. Z&nbsp;twierdzenia L22, w&nbsp;przypadku nieparzystego <math>n = p</math>, otrzymujemy
+
Zauważmy, że modulo <math>21</math> ciąg <math>(a_k) = (1, - 3, 5, - 7, \ldots, 37, - 39, 41)</math> jest identyczny z&nbsp;ciągiem <math>(0, 1, 2, \ldots, 19, 20)</math>, a&nbsp;ciąg <math>(| a_k |)</math> to kolejne liczby nieparzyste od <math>1</math> do <math>2 m - 1</math>.
  
::<math>2^{p - 1} U_p = p P^{p - 1} + \binom{p}{3} P^{p - 3} D + \binom{p}{5} P^{p - 5} D^2 + \ldots + \binom{p}{p-2} P^2 D^{(p - 3) / 2} + D^{(p - 1) / 2}</math>
 
  
Ponieważ dla każdego <math>k \in [1, p - 1]</math> (zobacz L58)
+
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
  
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
+
::<math>m = 3 , \;\; (5 \mid 3) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
to modulo <math>p</math> dostajemy
+
::<math>m = 5 , \;\; (5 \mid 5) = 0 , \;\; (- 7 \mid 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(5 \mid 5) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
::<math>2^{p - 1} U_p \equiv U_p \equiv D^{(p - 1) / 2} \equiv (D \, | \, p) \pmod{p}</math>
+
::<math>m = 7 , \;\; (5 \mid 7) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
'''Punkt 2.'''
+
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
  
Zauważmy, że warunek <math>(D \, | \, p) = - 1</math> nie może być spełniony, gdy <math>p \, | \, Q</math>. Istotnie, gdy <math>p \, | \, Q</math>, to <math>D = P^2 - 4 Q \equiv P^2 \pmod{p}</math>, czyli
+
::<math>m = 11 , \;\; (- 11 \mid 11) = 0 , \;\; (13 \mid 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \mid 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
::<math>(D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 0 , \;</math> gdy <math>p \, | \, P</math>
+
::<math>m = 13 , \;\; (5 \mid 13) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
lub
+
::<math>m = 15 , \;\; \boldsymbol{(5 \mid 15) = 0} , \;\; (13 \mid 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
  
::<math>(D \, | \, p) = (P^2 \, | \, p) = (P \, | \, p)^2 = 1 , \;</math> gdy <math>p \nmid P</math>
+
::<math>m = 17 , \;\; (5 \mid 17) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
  
i nie może być <math>(D \, | \, p) = - 1</math>.
+
::<math>m = 19 , \;\; (- 7 \mid 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
Dla parzystego <math>n = p + 1</math> otrzymujemy z&nbsp;twierdzenia L22
+
::<math>m = 21 , \;\; \boldsymbol{(- 7 \mid 21) = 0} , \;\; (- 11 \mid 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
  
::<math>2^p U_{p + 1} = (p + 1) P^p + \binom{p + 1}{3} P^{p - 2} D + \binom{p + 1}{5} P^{p - 4} D^2 + \ldots + \binom{p + 1}{p - 2} P^3 D^{(p - 3) / 2} + (p + 1) P D^{(p - 1) / 2}</math>
 
  
Ponieważ dla <math>k \in [2, p - 1]</math> (zobacz L59)
+
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>(5, - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \mid m) = - 1</math>. Warunek <math>(a_k \mid m) = 0</math> oznacza, że <math>(2 k + 1 \mid m) = 0</math>, bo
  
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
+
::<math>(a_k \mid m) = ((- 1)^k (2 k + 1) \mid m) = ((- 1)^k \mid m) \cdot (2 k + 1 \mid m) = (- 1 \mid m)^k \cdot (2 k + 1 \mid m) = \pm (2 k + 1 \mid m)</math>
  
to modulo <math>p</math> dostajemy
+
Jeżeli będą spełnione warunki <math>(a_k \mid m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
  
::<math>2 U_{p + 1} \equiv P + P D^{(p - 1) / 2} \pmod{p}</math>
+
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
  
 +
::<math>r = 1 , \;\; a_{r + 1} = 5</math>
  
Z założenia <math>D</math> jest liczbą niekwadratową modulo <math>p</math>, zatem <math>D^{(p - 1) / 2} \equiv - 1 \pmod{p}</math>. Skąd wynika natychmiast, że
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \mid m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \mid m) = 0</math> || <math>5 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \mid m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = 5 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 +
|}
  
::<math>2 U_{p + 1} \equiv 0 \pmod{p}</math>
+
::<math>r = 2 , \;\; a_{r + 1} = - 7</math>
  
Czyli <math>p \, | \, U_{p + 1}</math>.
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \mid m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \mid m) = 0</math> || <math>7 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \mid m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = -7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 +
|}
  
'''Punkt 3.'''
+
::<math>r = 3</math>, <math>a_{r + 1} = 9</math>
  
Dla parzystego <math>n = p - 1</math> otrzymujemy z&nbsp;twierdzenia L22
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \mid m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \mid m) = 0</math> || <math>3 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \mid m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 +
|}
  
::<math>2^{p - 2} U_{p - 1} = (p - 1) P^{p - 2} + \binom{p - 1}{3} P^{p - 4} D + \binom{p - 1}{5} P^{p - 6} D^2 + \ldots + \binom{p - 1}{p - 4} P^3 D^{(p - 5) / 2} + (p - 1) P D^{(p - 3) / 2}</math>
 
  
Ponieważ dla <math>k \in [0, p - 1]</math> (zobacz L60)
+
Po wykonaniu trzech prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7</math>.
  
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
+
::<math>r</math>-ta próba, gdzie <math>r \geqslant 4 , \;\;</math> wyraz <math>a_{r + 1}</math>
  
to modulo <math>p</math> mamy
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \mid m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \mid m) = 0</math> || A. jeżeli <math>m \mid a_{r + 1}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 1}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \mid m</math><sup>( ** )</sup>, '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \mid m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 1}</math>, <math>Q = {\small\frac{1 - a_{r + 1}}{4}}</math>, '''koniec'''
 +
|}
  
::<math>2^{p - 2} U_{p - 1} \equiv - (P^{p - 2} + P^{p - 4} D + P^{p - 6} D^2 + \ldots + P D^{(p - 3) / 2}) \pmod{p}</math>
+
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 1} = a_{(m - 1) / 2} = m</math>
  
::::<math>\quad \,\, \equiv - P (P^{p - 3} + P^{p - 5} D + P^{p - 7} D^2 + \ldots + D^{(p - 3) / 2}) \pmod{p}</math>
+
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 1}</math>, to <math>\gcd (a_{r + 1}, m) = | a_{r + 1} |</math>, bo gdyby liczba <math>| a_{r + 1} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
  
  
Z założenia <math>D</math> jest liczbą kwadratową modulo <math>p</math>, zatem istnieje taka liczba <math>R</math>, że
+
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 5</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
  
::<math>D \equiv R^2 \pmod{p}</math>
+
::<math>| Q | = \left| {\small\frac{1 - a_{r + 1}}{4}} \right| \leqslant {\small\frac{| a_{r + 1} | + 1}{4}} = {\small\frac{2 r + 4}{4}} < 2 r + 5 \leqslant q</math>
  
Ponieważ
+
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
:* <math>(D \, | \, p) = 1</math>, to <math>p \nmid D</math>, zatem <math>p \nmid R</math>
 
:* z&nbsp;założenia <math>p \nmid Q</math>, to <math>P^2 - R^2 \equiv P^2 - D \equiv 4 Q \not\equiv 0 \pmod{p}</math>
 
  
  
Czyli
+
<span style="font-size: 110%; font-weight: bold;">Zadanie N31</span><br/>
 +
Zmodyfikujmy metodę Selfridge'a w&nbsp;taki sposób, że będziemy rozpoczynali próby nie od wyrazu <math>a_2 = 5</math>, ale od wyrazu <math>a_3 = - 7</math>. Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \mid m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej tak zmodyfikowaną metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
  
::<math>2^{p - 2} U_{p - 1} \equiv - P (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 +
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną zmodyfikowaną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
  
 +
::<math>m = 3 , \;\; (- 7 \mid 3) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
Uwzględniając, że <math>P^2 - R^2 \not\equiv 0 \pmod{p}</math>, możemy napisać
+
::<math>m = 5 , \;\; (- 7 \mid 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
::<math>2^{p - 2} (P^2 - R^2) U_{p - 1} \equiv - P (P^2 - R^2) (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p}</math>
+
::<math>m = 7 , \;\; (- 7 \mid 7) = 0 , \;\; (- 11 \mid 7) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1</math> (zauważmy, że <math>(- 7 \mid 7) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
::::::::<math>\equiv - P (P^{p - 1} - R^{p - 1}) \pmod{p}</math>
+
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
 
 
::::::::<math>\equiv 0 \pmod{p}</math>
 
  
Zauważmy, że wynik nie zależy od tego, czy <math>p \, | \, P</math>, czy <math>p \nmid P</math>. Skąd wynika
+
::<math>m = 11 , \;\; (- 11 \mid 11) = 0 , \;\; (13 \mid 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \mid 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
  
::<math>U_{p - 1} \equiv 0 \pmod{p}</math>
+
::<math>m = 13 , \;\; (- 7 \mid 13) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
Co należało pokazać.<br/>
+
::<math>m = 15 , \;\; \boldsymbol{(9 \mid 15) = 0} , \;\; (13 \mid 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
&#9633;
 
{{\Spoiler}}
 
  
 +
::<math>m = 17 , \;\; (- 7 \mid 17) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
 +
::<math>m = 19 , \;\; (- 7 \mid 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
  
Aby zapisać punkty 2. i 3. twierdzenia L34 (i tylko te punkty) w&nbsp;zwartej formie, musimy założyć, że <math>\gcd (p, D) = 1</math>. Otrzymujemy<br/>
+
::<math>m = 21 , \;\; \boldsymbol{(- 7 \mid 21) = 0} , \;\; (- 11 \mid 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L35</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą i <math>\gcd (p, Q D) = 1</math>, to
 
  
::<math>U_{p - (D \, | \, p)} \equiv 0 \pmod{p}</math>
 
  
 +
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>( - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \mid m) = - 1</math>. Warunek <math>(a_k \mid m) = 0</math> oznacza, że <math>(2 k + 1 \mid m) = 0</math>, bo
  
 +
::<math>(a_k \mid m) = ((- 1)^k (2 k + 1) \mid m) = ((- 1)^k \mid m) \cdot (2 k + 1 \mid m) = (- 1 \mid m)^k \cdot (2 k + 1 \mid m) = \pm (2 k + 1 \mid m)</math>
  
 +
Jeżeli będą spełnione warunki <math>(a_k \mid m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
  
 +
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
  
== Liczby pseudopierwsze Lucasa ==
+
::<math>r = 1 , \;\; a_{r + 2} = - 7</math>
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L36</span><br/>
+
::{| border="0"
Z twierdzenia L35 wiemy, że liczby pierwsze nieparzyste <math>p</math> takie, że <math>p \nmid Q D</math> są dzielnikami wyrazów ciągu Lucasa <math>U_{p - (D \, | \, p)}</math>, gdzie <math>(D \, | \, p)</math> oznacza symbol Legendre'a. Jeśli zastąpimy symbol Legendre'a symbolem Jacobiego, to będziemy mogli badać prawdziwość tego twierdzenia dla liczb złożonych i&nbsp;łatwo przekonamy się, że dla pewnych liczb złożonych <math>m</math> kongruencja
+
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \mid m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \mid m) = 0</math> || <math>7 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \mid m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = - 7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 +
|}
  
::<math>U_{m - (D \, | \, m)} \equiv 0 \pmod{m}</math>
+
::<math>r = 2 , \;\; a_{r + 2} = 9</math>
  
również jest prawdziwa. Prowadzi to definicji liczb pseudopierwszych Lucasa.
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \mid m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \mid m) = 0</math> || <math>3 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \mid m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 +
|}
  
 +
::<math>r = 3 , \;\; a_{r + 2} = - 11</math>
  
 +
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \mid m) = 1</math> || <math>11 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \mid m) = 0</math> || <math>11 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \mid m) = - 1 \quad</math> || <math>11 \nmid m</math> || <math>D = - 11 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;poprzedniej próbie, <math>r = 2</math>)
 +
|}
  
<span style="font-size: 110%; font-weight: bold;">Definicja L37</span><br/>
+
::<math>r = 4 , \;\; a_{r + 2} = 13</math>
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P</math> i <math>Q</math> (symbolicznie: LPSP( <math>P, Q</math> )), jeżeli <math>\gcd (m, Q D) = 1</math> i
 
  
::<math>U_{m - (D \, | \, m)} \equiv 0 \pmod{m}</math>
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \mid m) = 1</math> || <math>13 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \mid m) = 0</math> || <math>13 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \mid m) = - 1 \quad</math> || <math>13 \nmid m</math> || <math>D = 13 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;próbie o&nbsp;numerze <math>r = 2</math>)
 +
|}
  
gdzie <math>(D \, | \, m)</math> oznacza symbol Jacobiego.
+
::<math>r = 5 , \;\; a_{r + 2} = - 15</math>
  
 +
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \mid m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \mid m) = 0</math> || <math>5 \mid m</math> || '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \mid m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = - 15 , \;\; Q = 4 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 +
|}
  
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L38</span><br/>
+
Po wykonaniu pięciu prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7, 11, 13</math>.
Jeżeli liczba złożona nieparzysta <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, gdzie <math>a \geqslant 2</math>, to jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
+
::<math>r</math>-ta próba, gdzie <math>r \geqslant 6 , \;\;</math> wyraz <math>a_{r + 2}</math>
Połóżmy we wzorze definiującym ciąg Lucasa
 
  
::<math>U_m = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}}</math>
+
::{| border="0"
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \mid m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \mid m) = 0</math> || A. jeżeli <math>m \mid a_{r + 2}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 2}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \mid m</math><sup>( ** )</sup>, '''koniec'''
 +
|-style=height:2em
 +
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \mid m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 2}</math>, <math>Q = {\small\frac{1 - a_{r + 2}}{4}}</math>, '''koniec'''
 +
|}
  
<math>\alpha = a</math> i <math>\beta = 1</math>. Odpowiada to parametrom <math>P = \alpha + \beta = a + 1</math>, <math>Q = \alpha \beta = a</math>, <math>D = (\alpha - \beta)^2 = (a - 1)^2</math>.
+
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 2} = a_{(m - 1) / 2} = m</math>
  
Ponieważ musi być <math>\gcd (m, Q D) = 1</math>, to mamy <math>\gcd (m, (a - 1) a) = 1</math> i&nbsp;wynika stąd, że <math>(D \, | \, m) = 1</math>. Z&nbsp;założenia <math>m</math> jest liczbą pseudopierwszą Lucasa dla parametrów <math>P = a + 1</math> i <math>Q = a</math>, zatem
+
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 2}</math>, to <math>\gcd (a_{r + 2}, m) = | a_{r + 2} |</math>, bo gdyby liczba <math>| a_{r + 2} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
  
::<math>U_{m - 1} (a + 1, a) \equiv 0 \pmod{m}</math>
 
  
Czyli
+
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 7</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
  
::<math>{\small\frac{a^{m - 1} - 1}{a - 1}} \equiv 0 \pmod{m}</math>
+
::<math>| Q | = \left| {\small\frac{1 - a_{r + 2}}{4}} \right| \leqslant {\small\frac{| a_{r + 2} | + 1}{4}} = {\small\frac{2 r + 6}{4}} < 2 r + 7 \leqslant q</math>
  
Jeżeli <math>m \biggr\rvert {\small\frac{a^{m - 1} - 1}{a - 1}}</math>, to tym bardziej <math>m \big\rvert (a^{m - 1} - 1)</math> i&nbsp;możemy napisać
+
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
 
 
::<math>a^{m - 1} - 1 \equiv 0 \pmod{m}</math>
 
 
 
Zatem <math>m</math> jest liczbą pseudopierwszą Fermata przy podstawie <math>a</math>. Co należało pokazać.<br/>
 
 
&#9633;
 
&#9633;
 
{{\Spoiler}}
 
{{\Spoiler}}
Linia 1356: Linia 1490:
  
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L39</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N32</span><br/>
Wykorzystując funkcje <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz L6, L30) możemy napisać prosty program, który sprawdza, czy dla liczby nieparzystej <math>m</math> prawdziwe jest twierdzenie L35.
+
Przyjmując metodę Selfridge'a wyboru parametrów <math>P, Q</math> dla testu Lucasa, możemy łatwo napisać odpowiedni program w&nbsp;PARI/GP testujący pierwszość liczb
  
  <span style="font-size: 90%; color:black;">isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q) =  
+
  <span style="font-size: 90%; color:black;">LucasTest(m) =  
 
  {
 
  {
  '''local'''(D, js);
+
  '''local'''(P, Q, X);
  D = P^2 - 4*Q;
+
  '''if'''( m % 2 == 0, '''return'''(m == 2) );
  '''if'''( gcd(m, 2*Q*D) > 1, '''return'''(0) );
+
  '''if'''( '''issquare'''(m), '''return'''(0) ); \\ sprawdzamy, czy m nie jest liczbą kwadratową
  js = jacobi(D, m);
+
X = MethodA(m);
  '''if'''( modLucas(m - js, P, Q, m)[1] == 0, '''return'''(1), '''return'''(0) );
+
P = X[1];
  }
+
  Q = X[2];
 +
'''if'''( P == 0, '''return'''(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
 +
  '''if'''( modLucas(m + 1, P, Q, m)[1] == 0, '''return'''(1), '''return'''(0) );
 +
  }</span>
 +
 
 +
 
 +
 
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga N33</span><br/>
 +
Najmniejsze liczby pseudopierwsze Lucasa, które pojawiają się przy zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
 +
 
 +
::<math>323, 377, 1159, 1829, 3827, 5459, 5777, 9071, 9179, 10877, 11419, 11663, 13919, 14839, 16109, 16211, 18407, 18971, 19043, 22499, \ldots</math>
 +
 
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 +
<span style="font-size: 90%; color:black;">'''forstep'''(k=1, 3*10^4, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
 +
<br/>
 +
{{\Spoiler}}
  
  
  
<span style="font-size: 110%; font-weight: bold;">Przykład L40</span><br/>
+
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
Poniższa tabela zawiera najmniejsze liczby pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
 
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
+
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>  
 
 
|-
 
|-
! <math>\boldsymbol{- 5}</math>
+
| #LPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>2</math> || <math>9</math> || <math>57</math> || <math>219</math> || <math>659</math> || <math>1911</math> || <math>5485</math>
| <math>253</math> || <math>121</math> || <math>57</math> || <math>217</math> || style="background-color: yellow" | <math>323</math> || <math>69</math> || <math>121</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>
+
|}
|-
+
 
! <math>\boldsymbol{- 4}</math>
 
| <math>9</math> || style="background-color: yellow" | <math>323</math> || <math>91</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 
|-
 
! <math>\boldsymbol{- 3}</math>
 
| <math>217</math> || <math>91</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math>
 
|-
 
! <math>\boldsymbol{- 2}</math>
 
| <math>341</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>39</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>15</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>85</math>
 
|-
 
! <math>\boldsymbol{- 1}</math>
 
| style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>15</math>
 
|-
 
! <math>\boldsymbol{1}</math>
 
| <math>25</math> || style="background-color: red" | <math></math> || <math>21</math> || style="background-color: yellow" | <math>65</math> || style="background-color: yellow" | <math>115</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{2}</math>
 
| <math>1541</math> || <math>9</math> || <math>341</math> || style="background-color: yellow" | <math>35</math> || <math>21</math> || <math>85</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{3}</math>
 
| style="background-color: yellow" | <math>629</math> || style="background-color: yellow" | <math>559</math> || <math>25</math> || <math>91</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{4}</math>
 
| style="background-color: yellow" | <math>119</math> || <math>25</math> || style="background-color: yellow" | <math>209</math> || style="background-color: red" | <math></math> || <math>85</math> || <math>21</math> || style="background-color: yellow" | <math>119</math> || style="background-color: yellow" | <math>65</math> || <math>9</math> || style="background-color: yellow" | <math>115</math>
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>9</math> || style="background-color: yellow" | <math>143</math> || <math>49</math> || style="background-color: yellow" | <math>143</math> || style="background-color: yellow" | <math>323</math> || <math>217</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 
|}
 
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
  <span style="font-size: 90%; color:black;">FirstLPSP(Stop) =
+
  <span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n= ", n, "  ", s) )</span>
\\ najmniejsze LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
{
 
'''local'''(D, m, P, Q);
 
Q = -6;
 
'''while'''( Q++ <= 5,
 
        '''if'''( Q == 0, '''next'''() );
 
        P = 0;
 
        '''while'''( P++ <= 10,
 
              D = P^2 - 4*Q;
 
              '''if'''( D == 0,
 
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
 
                  '''next'''();
 
                );
 
              m = 3;
 
              '''while'''( m < Stop,
 
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q) && !'''isprime'''(m),
 
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 
                          '''break'''();
 
                        );
 
                      m = m + 2;
 
                    );
 
            );
 
      );
 
}</span>
 
 
<br/>
 
<br/>
 
{{\Spoiler}}
 
{{\Spoiler}}
  
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \, | \, m) = - 1</math>.
 
  
  
  
<span style="font-size: 110%; font-weight: bold;">Przykład L41</span><br/>
 
Ilość liczb LPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
 
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
+
== Liczby silnie pseudopierwsze Lucasa ==
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+
 
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>  
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N34</span><br/>
|-
+
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math> oraz <math>p - (D \mid p) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą, to spełniony jest dokładnie jeden z&nbsp;warunków
! <math>\boldsymbol{- 5}</math>
+
 
| <math>4266</math> || <math>4935</math> || <math>4278</math> || <math>4981</math> || <math>6363</math> || <math>6028</math> || <math>5202</math> || <math>4426</math> || <math>5832</math> || <math>6027</math>
+
::<math>U_w \equiv 0 \pmod{p}</math>
|-
+
 
! <math>\boldsymbol{- 4}</math>
+
lub
| <math>4599</math> || <math>4152</math> || <math>9272</math> || <math>5886</math> || <math>6958</math> || <math>4563</math> || <math>5600</math> || <math>9509</math> || <math>7007</math> || <math>4142</math>  
+
 
|-
+
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> dla pewnego <math>k \in [0, r - 1]</math>
! <math>\boldsymbol{- 3}</math>
+
 
| <math>4265</math> || <math>5767</math> || <math>4241</math> || <math>5114</math> || <math>5859</math> || <math>7669</math> || <math>6083</math> || <math>6120</math> || <math>4420</math> || <math>5096</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
|-
+
Wiemy (zobacz N20), że jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math>, to <math>p \mid U_{p - (D \mid p)}</math>. Z&nbsp;założenia jest <math>p - (D \mid p) = 2^r w</math>, zatem <math>p \mid U_{2^r w}</math>. Ponieważ założyliśmy, że <math>p \nmid Q</math> i <math>p \nmid D</math>, to ze wzoru <math>V^2_n - D U^2_n = 4 Q^n</math> (zobacz N13 p.14) wynika natychmiast, że <math>p</math> nie może dzielić jednocześnie liczb <math>U_n</math> i <math>V_n</math>.
! <math>\boldsymbol{- 2}</math>
+
 
| <math>5361</math> || <math>4389</math> || <math>5063</math> || <math>5632</math> || <math>5364</math> || <math>5228</math> || <math>5859</math> || <math>10487</math> || <math>5370</math> || <math>9798</math>
+
Korzystając ze wzoru <math>U_{2 n} = U_n V_n</math> (zobacz N13 p.11), otrzymujemy
|-
+
 
! <math>\boldsymbol{- 1}</math>
+
::{| border="0"
| <math>4152</math> || <math>5886</math> || <math>4563</math> || <math>9509</math> || <math>4142</math> || <math>6273</math> || <math>5773</math> || <math>4497</math> || <math>5166</math> || <math>5305</math>
+
|-style=height:3em
|-
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \mid U_{2^r w} \;\; \Longleftrightarrow \;\; p \mid U_{2^{r - 1} w} \cdot V_{2^{r - 1} w} \quad</math> || Jeżeli <math>p \mid V_{2^{r - 1} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 1} w}</math>, to <math>p \mid U_{2^{r - 1} w}</math>.
! <math>\boldsymbol{1}</math>
+
|-style=height:3em
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>6567</math> || <math>7669</math> || <math>7131</math> || <math>10882</math> || <math>8626</math> || <math>8974</math> || <math>8509</math> || <math>8752</math>
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \mid U_{2^{r - 1} w} \;\; \Longleftrightarrow \;\; p \mid U_{2^{r - 2} w} \cdot V_{2^{r - 2} w} \quad</math> || Jeżeli <math>p \mid V_{2^{r - 2} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 2} w}</math>, to <math>p \mid U_{2^{r - 2} w}</math>.
|-
+
|-style=height:3em
! <math>\boldsymbol{2}</math>
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||  
| <math>7803</math> || <math>449152466</math> || <math>5597</math> || <math>5886</math> || <math>6509</math> || <math>5761</math> || <math>8115</math> || <math>6945</math> || <math>8380</math> || <math>7095</math>
+
|-style=height:3em
|-
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \mid U_{4 w} \;\; \Longleftrightarrow \;\; p \mid U_{2 w} \cdot V_{2 w}</math> || Jeżeli <math>p \mid V_{2 w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2 w}</math>, to <math>p \mid U_{2 w}</math>.
! <math>\boldsymbol{3}</math>
+
|-style=height:3em
| <math>5974</math> || <math>8768</math> || <math>282485800</math> || <math>5767</math> || <math>5651</math> || <math>5632</math> || <math>6640</math> || <math>5725</math> || <math>6058</math> || <math>7050</math>
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \mid U_{2 w} \;\; \Longleftrightarrow \;\; p \mid U_w \cdot V_w</math> || Jeżeli <math>p \mid V_w</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_w</math>, to <math>p \mid U_w</math>.
|-
 
! <math>\boldsymbol{4}</math>
 
| <math>10749</math> || <math>282485800</math> || <math>14425</math> || style="background-color: red" | <math></math> || <math>9735</math> || <math>6567</math> || <math>8164</math> || <math>7669</math> || <math>7608</math> || <math>7131</math>
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>5047</math> || <math>15127</math> || <math>6155</math> || <math>15127</math> || <math>4152</math> || <math>5146</math> || <math>4423</math> || <math>5526</math> || <math>6289</math> || <math>9509</math>  
 
 
|}
 
|}
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
+
Z powyższego wynika, że musi być spełniony jeden z wypisanych w twierdzeniu warunków.
<span style="font-size: 90%; color:black;">NumOfLPSP(Stop) =
+
 
\\ ilość liczb pseudopierwszych Lucasa LPSP(P,Q) < Stop; dla 1<=P<=10 i -5<=Q<=5
+
 
{
+
Zauważmy teraz, że jeżeli liczba pierwsza <math>p</math> dzieli <math>V_w</math>, to <math>p \nmid U_w</math>, bo <math>p</math> nie może jednocześnie być dzielnikiem liczb <math>U_w</math> i <math>V_w</math>.
'''local'''(D, m, P, Q);
+
 
Q = -6;
+
Zauważmy też, że jeżeli dla pewnego <math>k \in [1, r - 1]</math> liczba pierwsza <math>p</math> dzieli <math>V_{2^k w}</math>, to <math>p</math> nie dzieli żadnej liczby <math>V_{2^j w}</math> dla <math>j \in [0, k - 1] \;\; \text{i} \;\; p \nmid U_w</math>. Istotnie:
'''while'''( Q++ <= 5,
+
 
        '''if'''( Q == 0, '''next'''() );
+
::{| border="0"
        P = 0;
+
|-style=height:3em
        '''while'''( P++ <= 10,
+
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \mid V_{2^k w}</math>, to <math>p \nmid U_{2^k w} \;\; \text{i} \;\; U_{2^k w} = U_{2^{k - 1} w} V_{2^{k - 1} w}</math>, zatem <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 1} w} \;\; \text{i} \;\; V_{2^{k - 1} w}</math>
              D = P^2 - 4*Q;
+
|-style=height:3em
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
+
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2^{k - 1} w} \;\; \text{i} \;\; U_{2^{k - 1} w} = U_{2^{k - 2} w} V_{2^{k - 2} w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 2} w} \;\; \text{i} \;\; V_{2^{k - 2} w}</math>
              s = 0;
+
|-style=height:3em
              m = 3;
+
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||
              '''while'''( m < Stop,
+
|-style=height:3em
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">LPSP</span>(m, P, Q)  && !'''isprime'''(m), s++ );
+
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{4 w} \;\; \text{i} \;\; U_{4 w} = U_{2 w} V_{2 w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2 w} \;\; \text{i} \;\; V_{2 w}</math>
                      m = m + 2;
+
|-style=height:3em
                    );
+
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2 w} \;\; \text{i} \;\; U_{2 w} = U_w V_w</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_w \;\; \text{i} \;\; V_w</math>
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
+
|}
            );
 
      );
 
}</span>
 
<br/>
 
{{\Spoiler}}
 
  
  
 +
Co dowodzi, że spełniony jest dokładnie jeden z <math>r + 1</math> warunków:
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L42</span><br/>
+
::<math>U_w \equiv 0 \pmod{p}</math>
Dla <math>(P, Q) = (1, 1)</math> ciąg Lucasa <math>(U_n)</math> ma postać
 
  
::<math>(U_n) = (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, \ldots)</math>
+
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> gdzie <math>k \in [0, r - 1]</math>
  
Stosując indukcję matematyczną, udowodnimy, że <math>U_{3 k} = 0</math>. Łatwo sprawdzamy, że dla <math>k = 0</math> i <math>k = 1</math> wzór jest prawdziwy. Zakładając prawdziwość wzoru dla wszystkich liczb naturalnych nie większych od <math>k</math>, otrzymujemy dla <math>k + 1</math> (zobacz L28 p.3)
+
Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
::<math>U_{3 (k + 1)} = U_{3 k + 3} = U_{3 k} V_3 - U_{3 (k - 1)} = 0</math>
 
  
Co kończy dowód. Zbadajmy liczby pseudopierwsze Lucasa dla <math>(P, Q) = (1, 1)</math>.
 
  
Mamy <math>D = P^2 - 4 Q = - 3</math>. Wynika stąd, że nie może być <math>3 \, | \, m</math>, bo mielibyśmy <math>\gcd (m, Q D) = 3 > 1</math>.
+
Konsekwentnie definiujemy liczby pseudopierwsze<br/>
 +
<span style="font-size: 110%; font-weight: bold;">Definicja N35</span><br/>
 +
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą silnie pseudopierwszą Lucasa (SLPSP) dla parametrów <math>P</math> i <math>Q</math>, jeżeli <math>\gcd (m, Q D) = 1</math> oraz <math>m - (D \mid m) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą i&nbsp;spełniony jest jeden z&nbsp;warunków
  
Z zadania L4 wiemy, że
+
::<math>U_w \equiv 0 \pmod{m}</math>
  
::<math>(- 3 \, | \, m) =
+
lub
\begin{cases}
 
\;\;\: 1 & \text{gdy } m = 6 k + 1 \\
 
\;\;\: 0 & \text{gdy } m = 6 k + 3 \\
 
      - 1 & \text{gdy } m = 6 k + 5
 
\end{cases}</math>
 
  
Ponieważ <math>3 \nmid m</math>, to wystarczy zbadać przypadki <math>m = 6 k + 1</math> i <math>m = 6 k + 5</math>. W&nbsp;pierwszym przypadku jest
+
::<math>V_{2^k w} \equiv 0 \pmod{m} \;</math> dla pewnego <math>k \in [0, r - 1]</math>
  
::<math>U_{m - (- 3 \, | \, m)} = U_{6 k + 1 - 1} = U_{6 k} = 0</math>
 
  
W drugim przypadku, gdy <math>m = 6 k + 5</math>, dostajemy
 
  
::<math>U_{m - (- 3 \, | \, m)} = U_{6 k + 5 + 1} = U_{6 (k + 1)} = 0</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N36</span><br/>
 
+
Każda liczba SLPSP(<math>P, Q</math>) jest LPSP(<math>P, Q</math>). Korzystając ze zdefiniowanych wcześniej funkcji: <code>modPower(a, n, m)</code>, <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz M2, J48, N15), możemy napisać prosty program, który sprawdza, czy liczba <math>m</math> spełnia jeden z&nbsp;warunków podanych w&nbsp;twierdzeniu N34.
Zatem dla dowolnej liczby nieparzystej <math>m</math> niepodzielnej przez <math>3</math> jest
 
 
 
::<math>U_{m - (- 3 \, | \, m)} \equiv 0 \pmod{m}</math>
 
 
 
Czyli liczbami pseudopierwszymi Lucasa dla parametrów <math>(P, Q) = (1, 1)</math> będą liczby nieparzyste <math>m</math>, które nie są podzielne przez <math>3</math> i&nbsp;nie są liczbami pierwszymi. Ilość takich liczb nie większych od <math>10^k</math> możemy łatwo znaleźć poleceniem
 
 
 
'''for'''(k = 1, 9, s = 0; '''forstep'''(m = 3, 10^k, 2, '''if'''( m%6 <> 3, s = s + !'''isprime'''(m) )); '''print'''(s))
 
  
 +
<span style="font-size: 90%; color: black;">isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q) =
 +
{
 +
'''local'''(a, b, c, D, js, k, r, w, X);
 +
D = P^2 - 4*Q;
 +
'''if'''( gcd(m, 2*Q*D) > 1, '''return'''(0) );
 +
js = jacobi(D, m);
 +
r = '''valuation'''(m - js, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m - js
 +
w = (m - js) / 2^r;
 +
X =  modLucas(w, P, Q, m);
 +
a = X[1]; \\ U_w(P, Q) % m
 +
b = X[2]; \\ V_w(P, Q) % m
 +
'''if'''( a == 0 || b == 0, '''return'''(1) ); \\ b == 0 to przypadek k == 0
 +
'''if'''( r == 1, '''return'''(0) ); \\ nie ma dalszych przypadków
 +
c = modPower(Q, w, m); \\ Q^w % m
 +
k = 0;
 +
\\ sprawdzamy warunek V_(2^k * w) % m = 0; korzystamy ze wzoru V_(2*t) = (V_t)^2 - 2*Q^t
 +
'''while'''( k++ < r,
 +
        b = (b^2 - 2*c) % m;
 +
        '''if'''( b == 0, '''return'''(1) );
 +
        c = c^2 % m;
 +
      );
 +
'''return'''(0);
 +
}</span>
  
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L43</span><br/>
 
Pokazać, że ilość liczb pseudopierwszych Lucasa dla parametrów <math>(P, Q) = (2, 2)</math> nie większych od <math>10^k</math> możemy znaleźć poleceniem
 
  
'''for'''(k = 1, 9, s = 0; '''forstep'''(m = 3, 10^k, 2, s = s + !'''isprime'''(m)); '''print'''(s))
+
<span style="font-size: 110%; font-weight: bold;">Przykład N37</span><br/>
 +
Poniższa tabela zawiera najmniejsze liczby silnie pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
  
 
+
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 
+
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
+
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
 
+
|-
== Metoda Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math> ==
+
! <math>\boldsymbol{- 5}</math>
 
+
| <math>253</math> || <math>121</math> || style="background-color: yellow" | <math>143</math> || <math>781</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>299</math> || <math>121</math> || style="background-color: yellow" | <math>407</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>  
<span style="font-size: 110%; font-weight: bold;">Uwaga L44</span><br/>
+
|-
Twierdzenie L35 możemy wykorzystać do testowania pierwszości liczb. Ponieważ musi być spełniony warunek <math>\gcd (m, Q D) = 1</math>, to nie każda para liczb <math>P, Q</math> (np. wybrana losowo) nadaje się do przeprowadzenia testu. Zawsze będziemy zmuszeni określić zasadę postępowania, która doprowadzi do wyboru właściwej pary <math>P, Q</math>.
+
! <math>\boldsymbol{- 4}</math>
 
+
| <math>9</math> || <math>4181</math> || <math>341</math> || <math>169</math> || <math>33</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>  
Robert Baillie i&nbsp;Samuel Wagstaff przedstawili<ref name="BaillieWagstaff1"/> dwie metody wyboru parametrów dla testu Lucasa. Ograniczymy się do omówienia tylko pierwszej z&nbsp;nich (metodę zaproponował John Selfridge).
+
|-
 
+
! <math>\boldsymbol{- 3}</math>
Rozważmy ciąg <math>a_k = (- 1)^k (2 k + 1)</math>, gdzie <math>k \geqslant 2</math>, czyli <math>a_k = (5, - 7, 9, - 11, 13, - 15, \ldots)</math>. Niech <math>D</math> będzie pierwszym wyrazem ciągu <math>(a_k)</math>, dla którego jest <math>(a_k \, | \, m) = - 1</math>. Dla tak ustalonego <math>D</math> przyjmujemy <math>P = 1</math> i <math>Q = (1 - D) / 4</math>.
+
| style="background-color: yellow" | <math>799</math> || <math>121</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || <math>85</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>55</math> || style="background-color: yellow" | <math>35</math> || <math>169</math> || <math>529</math>  
 
+
|-
Tabela przedstawia początkowe wartości <math>Q</math>, jakie otrzymamy, stosując tę metodę.
+
! <math>\boldsymbol{- 2}</math>
 
+
| <math>2047</math> || style="background-color: yellow" | <math>989</math> || <math>161</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>265</math>  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
! <math>\boldsymbol{k}</math>  
 
| <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
 
 
|-
 
|-
! <math>\boldsymbol{a_k}</math>  
+
! <math>\boldsymbol{- 1}</math>
| <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
+
| <math>4181</math> || <math>169</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>629</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>51</math>  
 
|-
 
|-
! <math>\boldsymbol{Q}</math>  
+
! <math>\boldsymbol{1}</math>
| <math>-1</math> || <math>2</math> || style="background-color: red" | <math>-2</math> || <math>3</math> || <math>-3</math> || <math>4</math> || <math>-4</math> || <math>5</math> || <math>-5</math> || <math>6</math> || style="background-color: red" | <math>-6</math> || <math>7</math> || <math>-7</math> || <math>8</math> || <math>-8</math> || <math>9</math> || <math>-9</math> || <math>10</math> || <math>-10</math>
+
| <math>25</math> || style="background-color: red" | <math></math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>527</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>559</math> || <math>9</math> || <math>49</math>
|}
+
|-
 
+
! <math>\boldsymbol{2}</math>
 
+
| style="background-color: yellow" | <math>5459</math> || <math>9</math> || <math>2047</math> || <math>169</math> || <math>21</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || <math>49</math>
Zauważmy, że
+
|-
:* jeżeli liczba nieparzysta <math>m</math> jest liczbą kwadratową, to wybór <math>D</math> nie będzie możliwy
+
! <math>\boldsymbol{3}</math>
:* w&nbsp;przypadku zastosowania tej metody znajdziemy tylko liczby pierwsze lub pseudopierwsze Lucasa, które spełniają kongruencję <math>U_{m + 1} \equiv 0 \pmod{m}</math>, czyli tylko część liczb pseudopierwszych Lucasa określonych w&nbsp;definicji L37
+
| style="background-color: yellow" | <math>899</math> || style="background-color: yellow" | <math>5983</math> || <math>25</math> || <math>121</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>
 
+
|-
 +
! <math>\boldsymbol{4}</math>
 +
| style="background-color: yellow" | <math>899</math> || <math>25</math> || <math>1541</math> || style="background-color: red" | <math></math> || <math>341</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>377</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>527</math>  
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>9</math> || style="background-color: yellow" | <math>527</math> || <math>49</math> || style="background-color: yellow" | <math>527</math> || <math>4181</math> || <math>781</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>  
 +
|}
  
Ponieważ Baillie i&nbsp;Wagstaff określili metodę zaproponowaną przez Selfridge'a jako metodę A, to pozostaniemy przy tej nazwie. Korzystając ze wzoru rekurencyjnego
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
+
  <span style="font-size: 90%; color:black;">FirstSLPSP(Stop) =  
::<math> a_{k+1} =
+
\\ najmniejsze SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
  \begin{cases}
 
  \qquad \qquad 5 & \text{gdy } k = 1\\
 
      - a_k - 2 * \mathop{\textnormal{sign}}( a_k ) & \text{gdy } k \geqslant 2
 
  \end{cases}</math>
 
 
 
możemy łatwo napisać odpowiednią funkcję znajdującą liczby <math>P, Q</math> według tej metody.
 
 
 
  <span style="font-size: 90%; color:black;">MethodA(m) =  
 
 
  {
 
  {
  '''local'''(a, js);
+
  '''local'''(D, m, P, Q);
  a = 5;
+
  Q = -6;
  '''while'''( 1,
+
  '''while'''( Q++ <= 5,
         js = jacobi(a, m);
+
         '''if'''( Q == 0, '''next'''() );
         '''if'''( js == 0  &&  a % m <> 0, '''return'''([0, 0]) );
+
        P = 0;
        '''if'''( js == -1, '''return'''([1, (1 - a)/4]) );
+
         '''while'''( P++ <= 10,
        a = -a - 2*'''sign'''(a);
+
              D = P^2 - 4*Q;
 +
              '''if'''( D == 0,  
 +
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
 +
                  '''next'''();
 +
                );
 +
              m = 3;
 +
              '''while'''( m < Stop,
 +
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  &&  !'''isprime'''(m),  
 +
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 +
                          '''break'''();
 +
                        );
 +
                      m = m + 2;
 +
                    );
 +
            );
 
       );
 
       );
 
  }</span>
 
  }</span>
 +
<br/>
 +
{{\Spoiler}}
  
Wyjaśnienia wymaga druga linia kodu w&nbsp;pętli <code>while</code>. Wiemy, że (zobacz L3)
+
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \mid m) = - 1</math>.
  
::<math>(a \, | \, m) = 0 \quad \qquad \Longleftrightarrow \quad \qquad \gcd (a, m) > 1</math>
 
  
Jednak z&nbsp;faktu, że <math>\gcd (a, m) > 1</math> nie wynika natychmiast, że liczba <math>m</math> jest liczbą złożoną. Rozważmy dwa przypadki: gdy <math>m \, | \, a</math> i <math>m \nmid a</math>.
 
  
Gdy <math>\gcd (a, m) > 1</math> i <math>m \, | \, a</math>, to <math>\gcd (a, m) = \gcd (k \cdot m, m) = m > 1</math> i&nbsp;nie jesteśmy w&nbsp;stanie rozstrzygnąć, czy liczba <math>m</math> jest liczbą pierwszą, czy złożoną. Widać to dobrze na prostych przykładach
+
<span style="font-size: 110%; font-weight: bold;">Przykład N38</span><br/>
 +
Ilość liczb SLPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
  
::<math>\gcd (7, 7) = \gcd (14, 7) = 7 > 1</math>
+
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 
+
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
::<math>\gcd (15, 15) = \gcd (30, 15) = 15 > 1</math>
+
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>  
 
+
|-
Gdy <math>\gcd (a, m) > 1</math> i <math>m \nmid a</math>, to <math>m</math> jest liczbą złożoną. Ponieważ <math>m \nmid a</math>, to <math>a = k \cdot m + r</math>, gdzie <math>r \in [1, m - 1]</math>. Mamy
+
! <math>\boldsymbol{- 5}</math>
 
+
| <math>1056</math> || <math>1231</math> || <math>1184</math> || <math>1264</math> || <math>2278</math> || <math>1284</math> || <math>1181</math> || <math>1174</math> || <math>1281</math> || <math>1429</math>  
::<math>\gcd (a, m) = \gcd (k \cdot m + r, m) = \gcd (r, m) = d</math>
+
|-
 
+
! <math>\boldsymbol{- 4}</math>
Musi być <math>d > 1</math>, bo założyliśmy, że <math>\gcd (a, m) > 1</math> i&nbsp;musi być <math>d < m</math>, bo <math>d \leqslant r \leqslant m - 1</math>. Zatem <math>d</math> jest dzielnikiem nietrywialnym liczby <math>m</math> i <math>m</math> jest liczbą złożoną.
+
| <math>1043</math> || <math>1165</math> || <math>2139</math> || <math>1316</math> || <math>1151</math> || <math>1079</math> || <math>1112</math> || <math>2377</math> || <math>1197</math> || <math>989</math>  
 
+
|-
Omawiana linia kodu zapewnia wysłanie informacji o&nbsp;tym, że liczba <math>m</math> jest liczbą złożoną (zwrot wektora [0, 0]). W&nbsp;przypadku, gdy nie mamy takiej pewności, kontynuujemy szukanie liczby <math>a</math>, takiej że <math>(a \, | \, m) = - 1</math>, pozostawiając zbadanie pierwszości liczby <math>m</math> na kolejnym etapie testowania.
+
! <math>\boldsymbol{- 3}</math>
 
+
| <math>952</math> || <math>1514</math> || <math>1055</math> || <math>1153</math> || <math>1135</math> || <math>2057</math> || <math>998</math> || <math>1202</math> || <math>1077</math> || <math>1112</math>  
 
+
|-
Uważny Czytelnik dostrzeże, że nie zbadaliśmy, czy spełniony jest warunek <math>\gcd (m, Q) = 1</math>. Nie musimy tego robić, bo zwracana przez funkcję <code>MethodA()</code> liczba <math>Q</math> jest względnie pierwsza z <math>m</math>. Omówimy ten problem dokładnie w&nbsp;zadaniu L45. Poniżej pokażemy, że nawet gdyby było <math>\gcd (m, Q) > 1</math>, to złożona liczba <math>m</math> nie zostanie uznana za liczbę pseudopierwszą Lucasa.
+
! <math>\boldsymbol{- 2}</math>
 
+
| <math>1282</math> || <math>1092</math> || <math>1212</math> || <math>1510</math> || <math>1155</math> || <math>1179</math> || <math>1173</math> || <math>2240</math> || <math>1089</math> || <math>2109</math>  
Zauważmy, że jeżeli <math>m</math> jest liczbą złożoną i&nbsp;ma dzielnik pierwszy <math>p < m</math>, który dzieli <math>Q</math>, to <math>p \, | \, Q</math> i <math>p \nmid P</math> (bo <math>P = 1</math>), zatem <math>p \nmid U_k</math> dla <math>k \geqslant 1</math> (zobacz L32), czyli nie może być
+
|-
 
+
! <math>\boldsymbol{- 1}</math>
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{m}</math>
+
| <math>1165</math> || <math>1316</math> || <math>1079</math> || <math>2377</math> || <math>989</math> || <math>1196</math> || <math>1129</math> || <math>1050</math> || <math>1055</math> || <math>1147</math>  
 
+
|-
bo mielibyśmy
+
! <math>\boldsymbol{1}</math>
 +
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>2278</math> || <math>2057</math> || <math>2113</math> || <math>2266</math> || <math>4053</math> || <math>2508</math> || <math>2285</math> || <math>3083</math>  
 +
|-
 +
! <math>\boldsymbol{2}</math>
 +
| <math>1776</math> || <math>449152466</math> || <math>1282</math> || <math>1316</math> || <math>1645</math> || <math>1413</math> || <math>1564</math> || <math>1595</math> || <math>1683</math> || <math>1435</math>  
 +
|-
 +
! <math>\boldsymbol{3}</math>
 +
| <math>1621</math> || <math>1553</math> || <math>282485800</math> || <math>1514</math> || <math>1530</math> || <math>1510</math> || <math>1588</math> || <math>1549</math> || <math>1468</math> || <math>1692</math>  
 +
|-
 +
! <math>\boldsymbol{4}</math>
 +
| <math>2760</math> || <math>282485800</math> || <math>2978</math> || style="background-color: red" | <math></math> || <math>2137</math> || <math>2278</math> || <math>1995</math> || <math>2057</math> || <math>2260</math> || <math>2113</math>  
 +
|-
 +
! <math>\boldsymbol{5}</math>
 +
| <math>1314</math> || <math>2392</math> || <math>1497</math> || <math>2392</math> || <math>1165</math> || <math>1268</math> || <math>1227</math> || <math>1411</math> || <math>1253</math> || <math>2377</math>
 +
|}
  
::<math>U_{m + 1} (1, Q) \equiv 0 \pmod{p}</math>
 
  
a to jest niemożliwe. Zatem program wykorzystujący twierdzenie L35 wykryje złożoność liczby <math>m</math>.
 
  
Łatwo pokażemy, że nie jest możliwe, aby liczba <math>m</math> była liczbą pierwszą i&nbsp;była dzielnikiem <math>Q</math>. Jeżeli <math>m</math> jest liczbą pierwszą, to istnieje dokładnie <math>\tfrac{m - 1}{2}</math> liczb kwadratowych modulo <math>p</math> i <math>\tfrac{m - 1}{2}</math> liczb niekwadratowych modulo <math>p</math>, zatem rozpoczynając od wyrazu <math>a_2</math> możemy dojść co najwyżej do wyrazu o&nbsp;indeksie <math>k = \tfrac{m - 1}{2} + 2</math>, czyli
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
+
<span style="font-size: 90%; color:black;">NumOfSLPSP(Stop) =
::<math>| a_k | \leqslant m + 4</math>
+
\\ ilość liczb silnie pseudopierwszych Lucasa SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
+
{
Skąd wynika, że
+
'''local'''(D, m, P, Q);
 +
Q = -6;
 +
'''while'''( Q++ <= 5,
 +
        '''if'''( Q == 0, '''next'''() );
 +
        P = 0;
 +
        '''while'''( P++ <= 10,
 +
              D = P^2 - 4*Q;
 +
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
 +
              s = 0;
 +
              m = 3;
 +
              '''while'''( m < Stop,
 +
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  && !'''isprime'''(m), s++ );
 +
                      m = m + 2;
 +
                    );
 +
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
 +
            );
 +
      );
 +
}</span>
 +
<br/>
 +
{{\Spoiler}}
  
::<math>| Q | = \left| {\small\frac{1 - a_k}{4}} \right| \leqslant {\small\frac{m + 5}{4}} < m</math>
 
  
Ostatnia nierówność jest prawdziwa dla <math>m > {\small\frac{5}{3}}</math>, czyli dla wszystkich liczb pierwszych. Ponieważ <math>| Q | < m</math>, w&nbsp;przypadku gdy <math>m</math> jest liczbą pierwszą, to <math>m</math> nie może być dzielnikiem liczby <math>Q</math>.
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga N39</span><br/>
 +
Można pokazać<ref name="Arnault1"/>, że dla liczby złożonej nieparzystej <math>m \neq 9</math> i&nbsp;ustalonego <math>D</math> ilość par <math>P, Q</math> takich, że
  
 +
:* <math>0 \leqslant P, Q < m</math>
 +
:* <math>\gcd (Q, m) = 1</math>
 +
:* <math>P^2 - 4 Q \equiv D \pmod{m}</math>
 +
:* <math>m</math> jest SLPSP(<math>P, Q</math>)
 +
 +
nie przekracza <math>\tfrac{4}{15} n</math>.
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L45</span><br/>
+
Nie dotyczy to przypadku, gdy <math>m = p (p + 2)</math> jest iloczynem liczb pierwszych bliźniaczych takich, że <math>(D \mid p) = - (D \mid p + 2) = - 1</math>, wtedy mamy słabsze oszacowanie: <math>\# (P, Q) \leqslant \tfrac{1}{2} n</math>. Zauważmy, że taką sytuację łatwo wykryć, bo w&nbsp;tym przypadku <math>m + 1 = (p + 1)^2</math> jest liczbą kwadratową.
Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \, | \, m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
 
Niech <math>m = 21</math>. Rozpoczniemy od przykładu liczb <math>a_k = (- 1)^k (2 k + 1)</math> dla <math>k = 0, 1, \ldots, m - 1</math>.
 
  
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: center; margin-right: auto;"
 
! <math>\boldsymbol{k}</math> !! <math>\boldsymbol{0}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{(m-1)/2}</math> !!  !!  !!  !!  !!  !!  !!  !!  !!  !! <math>\boldsymbol{m-1}</math>
 
|-
 
! <math>\boldsymbol{k}</math>
 
| <math>0</math> || <math>1</math> || <math>2</math> || <math>3</math> || <math>4</math> || <math>5</math> || <math>6</math> || <math>7</math> || <math>8</math> || <math>9</math> || <math>10</math> || <math>11</math> || <math>12</math> || <math>13</math> || <math>14</math> || <math>15</math> || <math>16</math> || <math>17</math> || <math>18</math> || <math>19</math> || <math>20</math>
 
|-
 
! <math>\boldsymbol{a_k}</math>
 
| <math>1</math> || <math>-3</math> || <math>5</math> || <math>-7</math> || <math>9</math> || <math>-11</math> || <math>13</math> || <math>-15</math> || <math>17</math> || <math>-19</math> || <math>21</math> || <math>-23</math> || <math>25</math> || <math>-27</math> || <math>29</math> || <math>-31</math> || <math>33</math> || <math>-35</math> || <math>37</math> || <math>-39</math> || <math>41</math>
 
|-
 
! <math>\boldsymbol{R_m(a_k)}</math>
 
| <math>1</math> || <math>18</math> || <math>5</math> || <math>14</math> || <math>9</math> || <math>10</math> || <math>13</math> || <math>6</math> || <math>17</math> || <math>2</math> || <math>0</math> || <math>19</math> || <math>4</math> || <math>15</math> || <math>8</math> || <math>11</math> || <math>12</math> || <math>7</math> || <math>16</math> || <math>3</math> || <math>20</math>
 
|}
 
  
Zauważmy, że modulo <math>21</math> ciąg <math>(a_k) = (1, - 3, 5, - 7, \ldots, 37, - 39, 41)</math> jest identyczny z&nbsp;ciągiem <math>(0, 1, 2, \ldots, 19, 20)</math>, a&nbsp;ciąg <math>(| a_k |)</math> to kolejne liczby nieparzyste od <math>1</math> do <math>2 m - 1</math>.
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N40</span><br/>
 +
Podobnie jak w&nbsp;przypadku liczb pseudopierwszych Lucasa LPSP(<math>P, Q</math>) tak i&nbsp;w&nbsp;przypadku liczb silnie pseudopierwszych Lucasa SLPSP(<math>P, Q</math>) możemy testować pierwszość liczby <math>m</math>, wybierając liczby <math>P, Q</math> losowo lub zastosować wybraną metodę postępowania. Przedstawiony poniżej program, to zmodyfikowany kod z uwagi N36. Teraz parametry <math>P, Q</math> są wybierane metodą Selfridge'a, a symbol Jacobiego <math>(D \mid m)</math> jest równy <math>- 1</math>.
  
 +
<span style="font-size: 90%; color:black;">StrongLucasTest(m) =
 +
{
 +
'''local'''(a, b, c, k, P, Q, r, w, X);
 +
'''if'''( m % 2 == 0, '''return'''(m == 2) );
 +
'''if'''( '''issquare'''(m), '''return'''(0) ); \\ sprawdzamy, czy liczba m nie jest kwadratowa
 +
X = MethodA(m);
 +
P = X[1];
 +
Q = X[2];
 +
'''if'''( P == 0 || '''gcd'''(m, 2*Q) > 1, '''return'''(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
 +
r = '''valuation'''(m + 1, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m + 1
 +
w = (m + 1) / 2^r;
 +
X =  modLucas(w, P, Q, m);
 +
a = X[1]; \\ U_w(P, Q) % m
 +
b = X[2]; \\ V_w(P, Q) % m
 +
'''if'''( a == 0 || b == 0, '''return'''(1) ); \\ b == 0 to przypadek k == 0
 +
'''if'''( r == 1, '''return'''(0) ); \\ nie ma dalszych przypadków
 +
c = modPower(Q, w, m); \\ Q^w % m
 +
k = 0;
 +
\\ sprawdzamy warunek V_(2^k * w) %m = 0; korzystamy ze wzoru V_(2*w) = (V_w)^2 - 2*Q^w
 +
'''while'''( k++ < r,
 +
        b = (b^2 - 2*c) % m;
 +
        '''if'''( b == 0, '''return'''(1) );
 +
        c = c^2 % m;
 +
      );
 +
'''return'''(0);
 +
}</span>
  
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
 
 
::<math>m = 3 , \;\; (5 \, | \, 3) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
 
 
::<math>m = 5 , \;\; (5 \, | \, 5) = 0 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(5 \, | \, 5) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
 
 
::<math>m = 7 , \;\; (5 \, | \, 7) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
 
 
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
 
 
::<math>m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \, | \, 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
 
 
::<math>m = 13 , \;\; (5 \, | \, 13) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
 
 
::<math>m = 15 , \;\; \boldsymbol{(5 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
 
  
::<math>m = 17 , \;\; (5 \, | \, 17) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1</math>
 
  
::<math>m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N41</span><br/>
 +
Najmniejsze liczby silnie pseudopierwsze Lucasa, które otrzymujemy po zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
  
::<math>m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
+
::<math>5459, 5777, 10877, 16109, 18971, 22499, 24569, 25199, 40309, 58519, 75077, 97439, \ldots</math>
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 +
<span style="font-size: 90%; color:black;">'''forstep'''(k=1, 10^5, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
 +
<br/>
 +
{{\Spoiler}}
  
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>(5, - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \, | \, m) = - 1</math>. Warunek <math>(a_k \, | \, m) = 0</math> oznacza, że <math>(2 k + 1 \, | \, m) = 0</math>, bo
 
  
::<math>(a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m)</math>
+
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
  
Jeżeli będą spełnione warunki <math>(a_k \, | \, m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
+
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 +
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
 +
|-
 +
| #SLPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>0</math> || <math>2</math> || <math>12</math> || <math>58</math> || <math>178</math> || <math>505</math> || <math>1415</math>
 +
|}
  
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 +
<span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n=", n, "  ", s) )</span>
 +
<br/>
 +
{{\Spoiler}}
  
::<math>r = 1 , \;\; a_{r + 1} = 5</math>
 
  
::{| border="0"
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = 0</math> || <math>5 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(5 \, | \, m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = 5 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
 
::<math>r = 2 , \;\; a_{r + 1} = - 7</math>
 
  
::{| border="0"
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 0</math> || <math>7 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = -7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
  
::<math>r = 3</math>, <math>a_{r + 1} = 9</math>
 
  
::{| border="0"
+
== Test BPSW ==
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 0</math> || <math>3 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 
|}
 
  
 +
<span style="font-size: 110%; font-weight: bold;">Uwaga N42</span><br/>
 +
Jest <math>488</math> liczb SPSP(<math>2</math>) mniejszych od <math>10^8</math> i są 582 liczby SPSP(<math>3</math>) mniejsze od <math>10^8</math> (zobacz M21). Ale jest aż <math>21</math> liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>3</math>:
  
Po wykonaniu trzech prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7</math>.
+
<math>1373653, 1530787, 1987021, 2284453, 3116107, 5173601, 6787327, 11541307, 13694761, 15978007, 16070429,</math>
  
::<math>r</math>-ta próba, gdzie <math>r \geqslant 4 , \;\;</math> wyraz <math>a_{r + 1}</math>
+
<math>16879501, 25326001, 27509653, 27664033, 28527049, 54029741, 61832377, 66096253, 74927161, 80375707</math>
  
::{| border="0"
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
|-style=height:2em
+
  <span style="font-size: 90%; color:black;">'''forstep'''(m=3, 10^8, 2, '''if'''( isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2) &&  isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 3)  &&  !'''isprime'''(m), '''print'''("m=", m) ) )</span>
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp; || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
+
<br/>
|-style=height:2em
+
{{\Spoiler}}
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = 0</math> || A. jeżeli <math>m \, | \, a_{r + 1}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 1}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \, | \, m</math><sup>( ** )</sup>, '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 1} \, | \, m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 1}</math>, <math>Q = {\small\frac{1 - a_{r + 1}}{4}}</math>, '''koniec'''
 
|}
 
  
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 1} = a_{(m - 1) / 2} = m</math>
+
Widzimy, że prawdopodobieństwo błędnego rozpoznania pierwszości w&nbsp;przypadku liczb mniejszych od <math>10^8</math> dla podstawy <math>2</math> lub podstawy <math>3</math> jest rzędu kilku milionowych. Gdyby prawdopodobieństwa błędnego rozpoznania pierwszości w&nbsp;przypadku podstawy <math>2</math> lub podstawy <math>3</math> były niezależne, to spodziewalibyśmy się, że nie będzie wcale liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>3</math>, bo prawdopodobieństwo takiego zdarzenia byłoby równe kilkudziesięciu bilonowym. Ale tak nie jest.
  
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 1}</math>, to <math>\gcd (a_{r + 1}, m) = | a_{r + 1} |</math>, bo gdyby liczba <math>| a_{r + 1} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
+
Jest to mocny argument za tym, że zastosowanie różnych (niezależnych) testów może być znacznie silniejszym narzędziem do testowania pierwszości liczb, niż wielokrotne stosowanie tego samego testu, gdzie poszczególne próby są tylko pozornie niezależne.
  
 +
Połączenie znanych nam już testów prowadzi do prostego programu
  
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 1} | = 2 r + 3</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 5</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
+
<span style="font-size: 90%; color:black;">BPSWtest(m) =
 +
{
 +
'''forprime'''(p = 2, 1000, '''if'''( m % p > 0, '''next'''() ); '''if'''( m == p, '''return'''(1), '''return'''(0) ));
 +
'''if'''( !isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2), '''return'''(0) );
 +
'''if'''( !StrongLucasTest(m), '''return'''(0), '''return'''(1) );
 +
}</span>
  
::<math>| Q | = \left| {\small\frac{1 - a_{r + 1}}{4}} \right| \leqslant {\small\frac{| a_{r + 1} | + 1}{4}} = {\small\frac{2 r + 4}{4}} < 2 r + 5 \leqslant q</math>
 
  
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
 
&#9633;
 
{{\Spoiler}}
 
  
 +
Funkcja <code>BPSWtest(m)</code> kolejno sprawdza:
  
 +
:* czy liczba <math>m</math> jest podzielna przez niewielkie liczby pierwsze (w naszym przypadku mniejsze od <math>1000</math>); jeśli tak, to sprawdza, czy <math>m</math> jest liczbą pierwszą, czy złożoną i&nbsp;zwraca odpowiednio <math>1</math> lub <math>0</math>
 +
:* czy liczba <math>m</math> przechodzi test Millera-Rabina dla podstawy <math>2</math>; jeśli nie, to zwraca <math>0</math>
 +
:* czy liczba <math>m</math> przechodzi silny test Lucasa dla parametrów <math>P</math> i <math>Q</math>, które wybieramy metodą Selfridge'a; jeśli nie, to zwraca <math>0</math>, w&nbsp;przeciwnym wypadku zwraca <math>1</math>
  
<span style="font-size: 110%; font-weight: bold;">Zadanie L46</span><br/>
 
Zmodyfikujmy metodę Selfridge'a w&nbsp;taki sposób, że będziemy rozpoczynali próby nie od wyrazu <math>a_2 = 5</math>, ale od wyrazu <math>a_3 = - 7</math>. Pokazać, że w&nbsp;przypadku, gdy dla kolejnych liczb <math>a_k = (- 1)^k (2 k + 1)</math> sprawdzamy, czy konsekwencją <math>(a_k \, | \, m) = 0</math> jest złożoność liczby <math>m</math>, to dla każdej liczby <math>Q</math> wyznaczonej tak zmodyfikowaną metodą Selfridge'a jest <math>\gcd (Q, m) = 1</math>.
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Rozwiązanie|Hide=Ukryj rozwiązanie}}
+
Test w&nbsp;dokładnie takiej postaci zaproponowali Robert Baillie i&nbsp;Samuel Wagstaff<ref name="BaillieWagstaff1"/>. Nazwa testu to akronim, utworzony od pierwszych liter nazwisk Roberta Bailliego, Carla Pomerance'a, Johna Selfridge'a i&nbsp;Samuela Wagstaffa.
Poniżej pokażemy, dlaczego musi być <math>\gcd (Q, m) = 1</math>, gdzie <math>Q</math> jest liczbą wyznaczoną zmodyfikowaną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby <math>m</math> przy testowaniu kolejnych liczb <math>a_k</math>). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby <math>m</math>. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość <math>Q</math> na podstawie innego wyrazu ciągu <math>a_k</math> (ten symbol Jacobiego został zapisany zwykłą czcionką).
 
  
::<math>m = 3 , \;\; (- 7 \, | \, 3) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
Nie jest znany żaden przykład liczby złożonej <math>m</math>, którą test BPSW<ref name="BPSW1"/><ref name="BPSW2"/> identyfikowałby jako pierwszą i&nbsp;z&nbsp;pewnością nie ma takich liczb dla <math>m < 2^{64} \approx 1.844 \cdot 10^{19}</math>. Warto przypomnieć: potrzebowaliśmy siedmiu testów Millera-Rabina (dla podstaw <math>2, 3, 5, 7, 11, 13, 17</math>), aby mieć pewność, że dowolna liczba <math>m < 3.41 \cdot 10^{14}</math> jest pierwsza (zobacz M22).
  
::<math>m = 5 , \;\; (- 7 \, | \, 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
 
  
::<math>m = 7 , \;\; (- 7 \, | \, 7) = 0 , \;\; (- 11 \, | \, 7) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1</math> (zauważmy, że <math>(- 7 \, | \, 7) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
 
  
::<math>m = 9 , \;\; </math> (liczba kwadratowa)
 
  
::<math>m = 11 , \;\; (- 11 \, | \, 11) = 0 , \;\; (13 \, | \, 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\;</math> (zauważmy, że <math>(- 11 \, | \, 11) = 0</math> nie pozwala wnioskować o&nbsp;złożoności)
 
  
::<math>m = 13 , \;\; (- 7 \, | \, 13) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
== Uzupełnienia ==
  
::<math>m = 15 , \;\; \boldsymbol{(9 \, | \, 15) = 0} , \;\; (13 \, | \, 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
+
&nbsp;
  
::<math>m = 17 , \;\; (- 7 \, | \, 17) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
=== <span style="border-bottom:1px solid #000;">Pewne własności współczynników dwumianowych</span> ===
  
::<math>m = 19 , \;\; (- 7 \, | \, 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1</math>
+
&nbsp;
  
::<math>m = 21 , \;\; \boldsymbol{(- 7 \, | \, 21) = 0} , \;\; (- 11 \, | \, 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\;</math> (gdyby nie zbadano złożoności)
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N43</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą, to
  
 +
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
  
Niech <math>m \geqslant 23</math>. Wiemy, że w&nbsp;ciągu <math>( - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1)</math> wystąpią liczby <math>a_k</math> takie, że <math>(a_k \, | \, m) = - 1</math>. Warunek <math>(a_k \, | \, m) = 0</math> oznacza, że <math>(2 k + 1 \, | \, m) = 0</math>, bo
+
dla każdego <math>k \in [1, p - 1]</math>.
  
::<math>(a_k \, | \, m) = ((- 1)^k (2 k + 1) \, | \, m) = ((- 1)^k \, | \, m) \cdot (2 k + 1 \, | \, m) = (- 1 \, | \, m)^k \cdot (2 k + 1 \, | \, m) = \pm (2 k + 1 \, | \, m)</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Łatwo zauważamy, że dla <math>k \in [1, p - 1]</math> liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynnika dwumianowego
  
Jeżeli będą spełnione warunki <math>(a_k \, | \, m) = 0</math> i <math>R_m (a_k) \neq 0</math>, to liczba <math>m</math> będzie liczbą złożoną.
+
::<math>\binom{p}{k} = {\small\frac{p!}{k! \cdot (p - k)!}}</math>
  
Wypiszmy kolejne próby dla <math>m \geqslant 23</math>. Liczba <math>r</math> jest numerem próby.
+
zatem <math>p \biggr\rvert \binom{p}{k}</math>. Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
::<math>r = 1 , \;\; a_{r + 2} = - 7</math>
 
  
::{| border="0"
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 1</math> || <math>7 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = 0</math> || <math>7 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 7 \, | \, m) = - 1 \quad</math> || <math>7 \nmid m</math> || <math>D = - 7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
  
::<math>r = 2 , \;\; a_{r + 2} = 9</math>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N44</span><br/>
 +
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą, to
  
::{| border="0"
+
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 1</math> || <math>3 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) = 0</math> || <math>3 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(9 \, | \, m) \neq - 1 \quad</math> || - - - - || bo <math>9</math> jest liczbą kwadratową
 
|}
 
  
::<math>r = 3 , \;\; a_{r + 2} = - 11</math>
+
dla każdego <math>k \in [2, p - 1]</math>.
  
::{| border="0"
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
|-style=height:2em
+
Jeżeli <math>k \in [2, p - 1]</math>, to modulo <math>p</math> dostajemy
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = 1</math> || <math>11 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
+
 
|-style=height:2em
+
::<math>\binom{p + 1}{k} = \binom{p}{k} + \binom{p}{k - 1} \equiv 0 \pmod{p}</math>
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = 0</math> || <math>11 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 11 \, | \, m) = - 1 \quad</math> || <math>11 \nmid m</math> || <math>D = - 11 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;poprzedniej próbie, <math>r = 2</math>)
 
|}
 
  
::<math>r = 4 , \;\; a_{r + 2} = 13</math>
+
Bo liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynników dwumianowych po prawej stronie. Co należało pokazać.<br/>
 +
&#9633;
 +
{{\Spoiler}}
  
::{| border="0"
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = 1</math> || <math>13 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = 0</math> || <math>13 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(13 \, | \, m) = - 1 \quad</math> || <math>13 \nmid m</math> || <math>D = 13 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec''' (bo liczby złożone <math>m = 3 k</math> zostały usunięte w&nbsp;próbie o&nbsp;numerze <math>r = 2</math>)
 
|}
 
  
::<math>r = 5 , \;\; a_{r + 2} = - 15</math>
 
  
::{| border="0"
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N45</span><br/>
|-style=height:2em
+
Jeżeli <math>p</math> jest liczbą pierwszą, to
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = 1</math> || <math>5 \nmid m \quad</math> || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = 0</math> || <math>5 \, | \, m</math> || '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(- 15 \, | \, m) = - 1 \quad</math> || <math>5 \nmid m</math> || <math>D = - 15 , \;\; Q = 4 , \;\; \gcd (m, Q) = 1 , \;\;</math> '''koniec'''
 
|}
 
  
 +
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
  
Po wykonaniu pięciu prób niezakończonych sukcesem (tzn. wykryciem złożoności <math>m</math> lub ustaleniem wartości liczb <math>D</math> i <math>Q</math>) wiemy, że <math>m</math> nie jest podzielna przez żadną z&nbsp;liczb pierwszych <math>p = 3, 5, 7, 11, 13</math>.
+
dla każdego <math>k \in [0, p - 1]</math>.
  
::<math>r</math>-ta próba, gdzie <math>r \geqslant 6 , \;\;</math> wyraz <math>a_{r + 2}</math>
+
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Łatwo sprawdzamy, że twierdzenie jest prawdziwe dla liczby pierwszej parzystej <math>p = 2</math>. Załóżmy, że <math>p</math> jest liczbą pierwszą nieparzystą. Równie łatwo sprawdzamy, że twierdzenie jest prawdziwe dla <math>k = 0</math> i <math>k = 1</math>. Zauważmy, że dla <math>k \in [1, p - 1]</math> jest
  
::{| border="0"
+
::<math>\binom{p - 1}{k} = {\small\frac{(p - 1) !}{k! (p - 1 - k) !}} = {\small\frac{p - k}{k}} \cdot {\small\frac{(p - 1) !}{(k - 1) ! (p - k) !}} = {\small\frac{p - k}{k}} \cdot \binom{p - 1}{k - 1} = {\small\frac{p}{k}} \cdot \binom{p - 1}{k - 1} - \binom{p - 1}{k - 1}</math>
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = 1</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math>
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = 0</math> || A. jeżeli <math>m \, | \, a_{r + 2}</math><sup>( * )</sup><br/>B. jeżeli <math>m \nmid a_{r + 2}</math> || A. przechodzimy do kolejnego wyrazu ciągu <math>(a_k)</math> <br/> B. <math>a_{r + 1} \, | \, m</math><sup>( ** )</sup>, '''koniec'''
 
|-style=height:2em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>(a_{r + 2} \, | \, m) = - 1 \quad</math> || żadna liczba pierwsza <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m \quad</math> &nbsp;&nbsp;&nbsp;  || <math>D = a_{r + 2}</math>, <math>Q = {\small\frac{1 - a_{r + 2}}{4}}</math>, '''koniec'''
 
|}
 
  
<sup>( * )</sup> jest to możliwe tylko dla <math>a_{r + 2} = a_{(m - 1) / 2} = m</math>
+
Ponieważ współczynniki dwumianowe są liczbami całkowitymi, a&nbsp;liczba <math>k \in [2, p - 1]</math> nie dzieli liczby pierwszej nieparzystej <math>p</math>, to <math>k</math> musi dzielić liczbę <math>\binom{p - 1}{k - 1}</math>. Zatem dla <math>k \in [2, p - 1]</math> modulo <math>p</math> mamy
  
<sup>( ** )</sup> zauważmy, że jeżeli <math>m \nmid a_{r + 2}</math>, to <math>\gcd (a_{r + 2}, m) = | a_{r + 2} |</math>, bo gdyby liczba <math>| a_{r + 2} |</math> była liczbą złożoną, to żaden z&nbsp;jej dzielników pierwszych nie dzieliłby liczby <math>m</math>
+
::<math>\binom{p - 1}{k} \equiv - \binom{p - 1}{k - 1}\pmod{p}</math>
  
 +
Skąd otrzymujemy
  
Jeżeli nie została wykryta złożoność liczby <math>m</math>, to żadna z&nbsp;liczb pierwszych <math>p \leqslant | a_{r + 2} | = 2 r + 5</math> nie dzieli liczby <math>m</math>. Zatem <math>\gcd (Q, m) > 1</math> może być tylko w&nbsp;przypadku, gdy pewna liczba pierwsza <math>q \geqslant 2 r + 7</math> będzie wspólnym dzielnikiem liczb <math>Q</math> i <math>m</math>, ale jest to niemożliwe, bo
+
::<math>\binom{p - 1}{k} \equiv (- 1)^1 \binom{p - 1}{k - 1} \equiv (- 1)^2 \binom{p - 1}{k - 2} \equiv \ldots \equiv (- 1)^{k - 2} \binom{p - 1}{2} \equiv (- 1)^{k - 1} \binom{p - 1}{1} \equiv (- 1)^k \pmod{p}</math>
 
 
::<math>| Q | = \left| {\small\frac{1 - a_{r + 2}}{4}} \right| \leqslant {\small\frac{| a_{r + 2} | + 1}{4}} = {\small\frac{2 r + 6}{4}} < 2 r + 7 \leqslant q</math>
 
  
Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich <math>r</math> naturalnych.<br/>
+
Co należało pokazać. Zobacz też zadanie H22.<br/>
 
&#9633;
 
&#9633;
 
{{\Spoiler}}
 
{{\Spoiler}}
Linia 1884: Linia 1965:
  
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L47</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Twierdzenie N46</span><br/>
Przyjmując metodę Selfridge'a wyboru parametrów <math>P, Q</math> dla testu Lucasa, możemy łatwo napisać odpowiedni program w&nbsp;PARI/GP testujący pierwszość liczb
+
Dla współczynników dwumianowych prawdziwe są następujące wzory
  
<span style="font-size: 90%; color:black;">LucasTest(m) =
+
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
{
 
'''local'''(P, Q, X);
 
'''if'''( m % 2 == 0, '''return'''(m == 2) );
 
'''if'''( '''issquare'''(m), '''return'''(0) ); \\ sprawdzamy, czy m nie jest liczbą kwadratową
 
X = MethodA(m);
 
P = X[1];
 
Q = X[2];
 
'''if'''( P == 0, '''return'''(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
 
'''if'''( modLucas(m + 1, P, Q, m)[1] == 0, '''return'''(1), '''return'''(0) );
 
}</span>
 
  
 +
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
  
 +
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 +
Ze wzoru dwumianowego
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L48</span><br/>
+
::<math>(a + b)^n = \sum_{k = 0}^{n} \binom{n}{k} a^{n - k} b^k</math>
Najmniejsze liczby pseudopierwsze Lucasa, które pojawiają się przy zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
 
  
::<math>323, 377, 1159, 1829, 3827, 5459, 5777, 9071, 9179, 10877, 11419, 11663, 13919, 14839, 16109, 16211, 18407, 18971, 19043, 22499, \ldots</math>
+
z łatwością otrzymujemy
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
+
::<math>(1 + 1)^n = \sum_{k = 0}^{n} \binom{n}{k} = 2^n</math>
<span style="font-size: 90%; color:black;">'''forstep'''(k=1, 3*10^4, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
 
<br/>
 
{{\Spoiler}}
 
  
 +
::<math>(1 - 1)^n = \sum_{k = 0}^{n} (- 1)^k \binom{n}{k} = 0</math>
  
 +
Obliczając sumę i&nbsp;różnicę powyższych wzorów mamy
  
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
+
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 + (- 1)^k) = 2 \underset{k \; \text{parzyste}}{\sum^n_{k = 0}} \binom{n}{k} = 2^n</math>
  
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
+
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 - (- 1)^k) = 2 \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^n</math>
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
 
|-
 
| #LPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>2</math> || <math>9</math> || <math>57</math> || <math>219</math> || <math>659</math> || <math>1911</math> || <math>5485</math>
 
|}
 
  
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
+
Skąd natychmiast wynika
<span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( LucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n= ", n, "  ", s) )</span>
 
<br/>
 
{{\Spoiler}}
 
  
 +
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
  
 
+
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
 
 
 
== Liczby silnie pseudopierwsze Lucasa ==
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L49</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math> oraz <math>p - (D \, | \, p) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą, to spełniony jest dokładnie jeden z&nbsp;warunków
 
 
 
::<math>U_w \equiv 0 \pmod{p}</math>
 
 
 
lub
 
 
 
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> dla pewnego <math>k \in [0, r - 1]</math>
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Wiemy (zobacz L35), że jeżeli <math>p</math> jest liczbą pierwszą nieparzystą taką, że <math>\gcd (p, Q D) = 1</math>, to <math>p \, | \, U_{p - (D \, | \, p)}</math>. Z&nbsp;założenia jest <math>p - (D \, | \, p) = 2^r w</math>, zatem <math>p \, | \, U_{2^r w}</math>. Ponieważ założyliśmy, że <math>p \nmid Q</math> i <math>p \nmid D</math>, to ze wzoru <math>V^2_n - D U^2_n = 4 Q^n</math> (zobacz L28 p.14) wynika natychmiast, że <math>p</math> nie może dzielić jednocześnie liczb <math>U_n</math> i <math>V_n</math>.
 
 
 
Korzystając ze wzoru <math>U_{2 n} = U_n V_n</math> (zobacz L28 p.11), otrzymujemy
 
 
 
::{| border="0"
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2^r w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 1} w} \cdot V_{2^{r - 1} w} \quad</math> || Jeżeli <math>p \, | \, V_{2^{r - 1} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 1} w}</math>, to <math>p \, | \, U_{2^{r - 1} w}</math>.
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2^{r - 1} w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2^{r - 2} w} \cdot V_{2^{r - 2} w} \quad</math> || Jeżeli <math>p \, | \, V_{2^{r - 2} w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2^{r - 2} w}</math>, to <math>p \, | \, U_{2^{r - 2} w}</math>.
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{4 w} \;\; \Longleftrightarrow \;\; p \, | \, U_{2 w} \cdot V_{2 w}</math> || Jeżeli <math>p \, | \, V_{2 w}</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_{2 w}</math>, to <math>p \, | \, U_{2 w}</math>.
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>p \, | \, U_{2 w} \;\; \Longleftrightarrow \;\; p \, | \, U_w \cdot V_w</math> || Jeżeli <math>p \, | \, V_w</math>, to twierdzenie jest dowiedzione. Jeżeli <math>p \nmid V_w</math>, to <math>p \, | \, U_w</math>.
 
|}
 
 
 
Z powyższego wynika, że musi być spełniony jeden z wypisanych w twierdzeniu warunków.
 
 
 
 
 
Zauważmy teraz, że jeżeli liczba pierwsza <math>p</math> dzieli <math>V_w</math>, to <math>p \nmid U_w</math>, bo <math>p</math> nie może jednocześnie być dzielnikiem liczb <math>U_w</math> i <math>V_w</math>.
 
 
 
Zauważmy też, że jeżeli dla pewnego <math>k \in [1, r - 1]</math> liczba pierwsza <math>p</math> dzieli <math>V_{2^k w}</math>, to <math>p</math> nie dzieli żadnej liczby <math>V_{2^j w}</math> dla <math>j \in [0, k - 1] \;\; \text{i} \;\; p \nmid U_w</math>. Istotnie:
 
 
 
::{| border="0"
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \, | \, V_{2^k w}</math>, to <math>p \nmid U_{2^k w} \;\; \text{i} \;\; U_{2^k w} = U_{2^{k - 1} w} V_{2^{k - 1} w}</math>, zatem <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 1} w} \;\; \text{i} \;\; V_{2^{k - 1} w}</math>
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2^{k - 1} w} \;\; \text{i} \;\; U_{2^{k - 1} w} = U_{2^{k - 2} w} V_{2^{k - 2} w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2^{k - 2} w} \;\; \text{i} \;\; V_{2^{k - 2} w}</math>
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || <math>.................</math> ||
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{4 w} \;\; \text{i} \;\; U_{4 w} = U_{2 w} V_{2 w}</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_{2 w} \;\; \text{i} \;\; V_{2 w}</math>
 
|-style=height:3em
 
| &#9679;&nbsp;&nbsp;&nbsp; || jeżeli <math>p \nmid U_{2 w} \;\; \text{i} \;\; U_{2 w} = U_w V_w</math>, to <math>p</math> nie może być dzielnikiem żadnej z liczb <math>U_w \;\; \text{i} \;\; V_w</math>
 
|}
 
 
 
 
 
Co dowodzi, że spełniony jest dokładnie jeden z <math>r + 1</math> warunków:
 
 
 
::<math>U_w \equiv 0 \pmod{p}</math>
 
 
 
::<math>V_{2^k w} \equiv 0 \pmod{p} \qquad</math> gdzie <math>k \in [0, r - 1]</math>
 
 
 
Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
Konsekwentnie definiujemy liczby pseudopierwsze<br/>
 
<span style="font-size: 110%; font-weight: bold;">Definicja L50</span><br/>
 
Powiemy, że liczba złożona nieparzysta <math>m</math> jest liczbą silnie pseudopierwszą Lucasa (SLPSP) dla parametrów <math>P</math> i <math>Q</math>, jeżeli <math>\gcd (m, Q D) = 1</math> oraz <math>m - (D \, | \, m) = 2^r w</math>, gdzie <math>w</math> jest liczbą nieparzystą i&nbsp;spełniony jest jeden z&nbsp;warunków
 
 
 
::<math>U_w \equiv 0 \pmod{m}</math>
 
 
 
lub
 
 
 
::<math>V_{2^k w} \equiv 0 \pmod{m} \;</math> dla pewnego <math>k \in [0, r - 1]</math>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L51</span><br/>
 
Każda liczba SLPSP(<math>P, Q</math>) jest LPSP(<math>P, Q</math>). Korzystając ze zdefiniowanych wcześniej funkcji: <code>modPower(a, n, m)</code>, <code>jacobi(a, n)</code> i <code>modLucas(n, P, Q, m)</code> (zobacz K3, L6, L30), możemy napisać prosty program, który sprawdza, czy liczba <math>m</math> spełnia jeden z&nbsp;warunków podanych w&nbsp;twierdzeniu L49.
 
 
 
<span style="font-size: 90%; color: black;">isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q) =
 
{
 
'''local'''(a, b, c, D, js, k, r, w, X);
 
D = P^2 - 4*Q;
 
'''if'''( gcd(m, 2*Q*D) > 1, '''return'''(0) );
 
js = jacobi(D, m);
 
r = '''valuation'''(m - js, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m - js
 
w = (m - js) / 2^r;
 
X =  modLucas(w, P, Q, m);
 
a = X[1]; \\ U_w(P, Q) % m
 
b = X[2]; \\ V_w(P, Q) % m
 
'''if'''( a == 0 || b == 0, '''return'''(1) ); \\ b == 0 to przypadek k == 0
 
'''if'''( r == 1, '''return'''(0) ); \\ nie ma dalszych przypadków
 
c = modPower(Q, w, m); \\ Q^w % m
 
k = 0;
 
\\ sprawdzamy warunek V_(2^k * w) % m = 0; korzystamy ze wzoru V_(2*t) = (V_t)^2 - 2*Q^t
 
'''while'''( k++ < r,
 
        b = (b^2 - 2*c) % m;
 
        '''if'''( b == 0, '''return'''(1) );
 
        c = c^2 % m;
 
      );
 
'''return'''(0);
 
}</span>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Przykład L52</span><br/>
 
Poniższa tabela zawiera najmniejsze liczby silnie pseudopierwsze Lucasa dla różnych parametrów <math>P</math> i <math>Q</math>
 
 
 
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
 
|-
 
! <math>\boldsymbol{- 5}</math>
 
| <math>253</math> || <math>121</math> || style="background-color: yellow" | <math>143</math> || <math>781</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>299</math> || <math>121</math> || style="background-color: yellow" | <math>407</math> || <math>9</math> || style="background-color: yellow" | <math>143</math>
 
|-
 
! <math>\boldsymbol{- 4}</math>
 
| <math>9</math> || <math>4181</math> || <math>341</math> || <math>169</math> || <math>33</math> || style="background-color: yellow" | <math>119</math> || <math>57</math> || <math>9</math> || <math>9</math> || <math>9</math>
 
|-
 
! <math>\boldsymbol{- 3}</math>
 
| style="background-color: yellow" | <math>799</math> || <math>121</math> || style="background-color: yellow" | <math>527</math> || <math>25</math> || <math>85</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>55</math> || style="background-color: yellow" | <math>35</math> || <math>169</math> || <math>529</math>
 
|-
 
! <math>\boldsymbol{- 2}</math>
 
| <math>2047</math> || style="background-color: yellow" | <math>989</math> || <math>161</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>35</math> || <math>9</math> || <math>265</math>
 
|-
 
! <math>\boldsymbol{- 1}</math>
 
| <math>4181</math> || <math>169</math> || style="background-color: yellow" | <math>119</math> || <math>9</math> || <math>9</math> || style="background-color: yellow" | <math>629</math> || <math>25</math> || <math>33</math> || <math>9</math> || style="background-color: yellow" | <math>51</math>
 
|-
 
! <math>\boldsymbol{1}</math>
 
| <math>25</math> || style="background-color: red" | <math></math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>209</math> || style="background-color: yellow" | <math>527</math> || style="background-color: yellow" | <math>35</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>559</math> || <math>9</math> || <math>49</math>
 
|-
 
! <math>\boldsymbol{2}</math>
 
| style="background-color: yellow" | <math>5459</math> || <math>9</math> || <math>2047</math> || <math>169</math> || <math>21</math> || <math>253</math> || <math>9</math> || style="background-color: yellow" | <math>15</math> || <math>9</math> || <math>49</math>
 
|-
 
! <math>\boldsymbol{3}</math>
 
| style="background-color: yellow" | <math>899</math> || style="background-color: yellow" | <math>5983</math> || <math>25</math> || <math>121</math> || <math>49</math> || <math>49</math> || style="background-color: yellow" | <math>35</math> || <math>55</math> || <math>25</math> || style="background-color: yellow" | <math>35</math>
 
|-
 
! <math>\boldsymbol{4}</math>
 
| style="background-color: yellow" | <math>899</math> || <math>25</math> || <math>1541</math> || style="background-color: red" | <math></math> || <math>341</math> || style="background-color: yellow" | <math>323</math> || style="background-color: yellow" | <math>377</math> || style="background-color: yellow" | <math>209</math> || <math>9</math> || style="background-color: yellow" | <math>527</math>
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>9</math> || style="background-color: yellow" | <math>527</math> || <math>49</math> || style="background-color: yellow" | <math>527</math> || <math>4181</math> || <math>781</math> || style="background-color: yellow" | <math>39</math> || <math>9</math> || <math>9</math> || <math>9</math>
 
|}
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">FirstSLPSP(Stop) =
 
\\ najmniejsze SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
{
 
'''local'''(D, m, P, Q);
 
Q = -6;
 
'''while'''( Q++ <= 5,
 
        '''if'''( Q == 0, '''next'''() );
 
        P = 0;
 
        '''while'''( P++ <= 10,
 
              D = P^2 - 4*Q;
 
              '''if'''( D == 0,
 
                  '''print'''("Q= ", Q, "  P= ", P, "  ------------------");
 
                  '''next'''();
 
                );
 
              m = 3;
 
              '''while'''( m < Stop,
 
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  &&  !'''isprime'''(m),
 
                          '''print'''("Q= ", Q, "  P= ", P, "  m= ", m, "  (D|m)= ", jacobi(D, m));
 
                          '''break'''();
 
                        );
 
                      m = m + 2;
 
                    );
 
            );
 
      );
 
}</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których <math>(D \, | \, m) = - 1</math>.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Przykład L53</span><br/>
 
Ilość liczb SLPSP(<math>P, Q</math>) mniejszych od <math>10^9</math>
 
 
 
::{| class="wikitable plainlinks"  style="font-size: 100%; text-align: right; margin-right: auto;"
 
! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<math>\boldsymbol{P}</math><br/><math>\boldsymbol{Q}</math>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
! <math>\boldsymbol{1}</math> !! <math>\boldsymbol{2}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math> !! <math>\boldsymbol{10}</math>
 
|-
 
! <math>\boldsymbol{- 5}</math>
 
| <math>1056</math> || <math>1231</math> || <math>1184</math> || <math>1264</math> || <math>2278</math> || <math>1284</math> || <math>1181</math> || <math>1174</math> || <math>1281</math> || <math>1429</math>
 
|-
 
! <math>\boldsymbol{- 4}</math>
 
| <math>1043</math> || <math>1165</math> || <math>2139</math> || <math>1316</math> || <math>1151</math> || <math>1079</math> || <math>1112</math> || <math>2377</math> || <math>1197</math> || <math>989</math>
 
|-
 
! <math>\boldsymbol{- 3}</math>
 
| <math>952</math> || <math>1514</math> || <math>1055</math> || <math>1153</math> || <math>1135</math> || <math>2057</math> || <math>998</math> || <math>1202</math> || <math>1077</math> || <math>1112</math>
 
|-
 
! <math>\boldsymbol{- 2}</math>
 
| <math>1282</math> || <math>1092</math> || <math>1212</math> || <math>1510</math> || <math>1155</math> || <math>1179</math> || <math>1173</math> || <math>2240</math> || <math>1089</math> || <math>2109</math>
 
|-
 
! <math>\boldsymbol{- 1}</math>
 
| <math>1165</math> || <math>1316</math> || <math>1079</math> || <math>2377</math> || <math>989</math> || <math>1196</math> || <math>1129</math> || <math>1050</math> || <math>1055</math> || <math>1147</math>
 
|-
 
! <math>\boldsymbol{1}</math>
 
| <math>282485800</math> || style="background-color: red" | <math></math> || <math>2278</math> || <math>2057</math> || <math>2113</math> || <math>2266</math> || <math>4053</math> || <math>2508</math> || <math>2285</math> || <math>3083</math>
 
|-
 
! <math>\boldsymbol{2}</math>
 
| <math>1776</math> || <math>449152466</math> || <math>1282</math> || <math>1316</math> || <math>1645</math> || <math>1413</math> || <math>1564</math> || <math>1595</math> || <math>1683</math> || <math>1435</math>
 
|-
 
! <math>\boldsymbol{3}</math>
 
| <math>1621</math> || <math>1553</math> || <math>282485800</math> || <math>1514</math> || <math>1530</math> || <math>1510</math> || <math>1588</math> || <math>1549</math> || <math>1468</math> || <math>1692</math>
 
|-
 
! <math>\boldsymbol{4}</math>
 
| <math>2760</math> || <math>282485800</math> || <math>2978</math> || style="background-color: red" | <math></math> || <math>2137</math> || <math>2278</math> || <math>1995</math> || <math>2057</math> || <math>2260</math> || <math>2113</math>
 
|-
 
! <math>\boldsymbol{5}</math>
 
| <math>1314</math> || <math>2392</math> || <math>1497</math> || <math>2392</math> || <math>1165</math> || <math>1268</math> || <math>1227</math> || <math>1411</math> || <math>1253</math> || <math>2377</math>
 
|}
 
 
 
 
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">NumOfSLPSP(Stop) =
 
\\ ilość liczb silnie pseudopierwszych Lucasa SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
 
{
 
'''local'''(D, m, P, Q);
 
Q = -6;
 
'''while'''( Q++ <= 5,
 
        '''if'''( Q == 0, '''next'''() );
 
        P = 0;
 
        '''while'''( P++ <= 10,
 
              D = P^2 - 4*Q;
 
              '''if'''( D == 0, '''print'''("Q= ", Q, "  P= ", P, "  ------------------"); '''next'''() );
 
              s = 0;
 
              m = 3;
 
              '''while'''( m < Stop,
 
                      '''if'''( isPrimeOr<span style="background-color: #fee481;">SLPSP</span>(m, P, Q)  &&  !'''isprime'''(m), s++ );
 
                      m = m + 2;
 
                    );
 
              '''print'''("Q= ", Q, "  P= ", P, "  s= ", s);
 
            );
 
      );
 
}</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L54</span><br/>
 
Można pokazać<ref name="Arnault1"/>, że dla liczby złożonej nieparzystej <math>m \neq 9</math> i&nbsp;ustalonego <math>D</math> ilość par <math>P, Q</math> takich, że
 
 
 
:* <math>0 \leqslant P, Q < m</math>
 
:* <math>\gcd (Q, m) = 1</math>
 
:* <math>P^2 - 4 Q \equiv D \pmod{m}</math>
 
:* <math>m</math> jest SLPSP(<math>P, Q</math>)
 
 
 
nie przekracza <math>\tfrac{4}{15} n</math>.
 
 
 
Nie dotyczy to przypadku, gdy <math>m = p (p + 2)</math> jest iloczynem liczb pierwszych bliźniaczych takich, że <math>(D \, | \, p) = - (D \, | \, p + 2) = - 1</math>, wtedy mamy słabsze oszacowanie: <math>\# (P, Q) \leqslant \tfrac{1}{2} n</math>. Zauważmy, że taką sytuację łatwo wykryć, bo w&nbsp;tym przypadku <math>m + 1 = (p + 1)^2</math> jest liczbą kwadratową.
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L55</span><br/>
 
Podobnie jak w&nbsp;przypadku liczb pseudopierwszych Lucasa LPSP(<math>P, Q</math>) tak i&nbsp;w&nbsp;przypadku liczb silnie pseudopierwszych Lucasa SLPSP(<math>P, Q</math>) możemy testować pierwszość liczby <math>m</math>, wybierając liczby <math>P, Q</math> losowo lub zastosować wybraną metodę postępowania. Przedstawiony poniżej program, to zmodyfikowany kod z uwagi L51. Teraz parametry <math>P, Q</math> są wybierane metodą Selfridge'a, a symbol Jacobiego <math>(D \, | \, m)</math> jest równy <math>- 1</math>.
 
 
 
<span style="font-size: 90%; color:black;">StrongLucasTest(m) =
 
{
 
'''local'''(a, b, c, k, P, Q, r, w, X);
 
'''if'''( '''issquare'''(m), '''return'''(0) ); \\ sprawdzamy, czy liczba m nie jest kwadratowa
 
X = MethodA(m);
 
P = X[1];
 
Q = X[2];
 
'''if'''( P == 0 || '''gcd'''(m, 2*Q) > 1, '''return'''(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
 
r = '''valuation'''(m + 1, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m + 1
 
w = (m + 1) / 2^r;
 
X =  modLucas(w, P, Q, m);
 
a = X[1]; \\ U_w(P, Q) % m
 
b = X[2]; \\ V_w(P, Q) % m
 
'''if'''( a == 0 || b == 0, '''return'''(1) ); \\ b == 0 to przypadek k == 0
 
'''if'''( r == 1, '''return'''(0) ); \\ nie ma dalszych przypadków
 
c = modPower(Q, w, m); \\ Q^w % m
 
k = 0;
 
\\ sprawdzamy warunek V_(2^k * w) %m = 0; korzystamy ze wzoru V_(2*w) = (V_w)^2 - 2*Q^w
 
'''while'''( k++ < r,
 
        b = (b^2 - 2*c) % m;
 
        '''if'''( b == 0, '''return'''(1) );
 
        c = c^2 % m;
 
      );
 
'''return'''(0);
 
}</span>
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L56</span><br/>
 
Najmniejsze liczby silnie pseudopierwsze Lucasa, które otrzymujemy po zastosowaniu metody Selfridge'a wyboru parametrów <math>P</math> i <math>Q</math>, to
 
 
 
::<math>5459, 5777, 10877, 16109, 18971, 22499, 24569, 25199, 40309, 58519, 75077, 97439, \ldots</math>
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">'''forstep'''(k=1, 10^5, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), '''print'''(k)) )</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
 
 
Tabela przedstawia ilość takich liczb nie większych od <math>10^n</math>
 
 
 
::{| class="wikitable plainlinks"  style="font-size: 90%; text-align: right; margin-right: auto;"
 
! <math>\boldsymbol{n}</math> !! <math>\boldsymbol{3}</math> !! <math>\boldsymbol{4}</math> !! <math>\boldsymbol{5}</math> !! <math>\boldsymbol{6}</math> !! <math>\boldsymbol{7}</math> !! <math>\boldsymbol{8}</math> !! <math>\boldsymbol{9}</math>
 
|-
 
| #SLPSP <math>< 10^n</math> (metoda Selfridge'a) || <math>0</math> || <math>2</math> || <math>12</math> || <math>58</math> || <math>178</math> || <math>505</math> || <math>1415</math>
 
|}
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">'''for'''(n=3, 9, s=0; '''forstep'''(k = 1, 10^n, 2, '''if'''( StrongLucasTest(k) && !'''isprime'''(k), s++ ) ); '''print'''("n=", n, "  ", s) )</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
 
 
 
 
 
 
 
 
== Test BPSW ==
 
 
 
<span style="font-size: 110%; font-weight: bold;">Uwaga L57</span><br/>
 
Jest <math>488</math> liczb SPSP(<math>2</math>) mniejszych od <math>10^8</math> i są 582 liczby SPSP(<math>3</math>) mniejsze od <math>10^8</math> (zobacz K21). Ale jest aż <math>21</math> liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>3</math>:
 
 
 
<math>1373653, 1530787, 1987021, 2284453, 3116107, 5173601, 6787327, 11541307, 13694761, 15978007, 16070429,</math>
 
 
 
<math>16879501, 25326001, 27509653, 27664033, 28527049, 54029741, 61832377, 66096253, 74927161, 80375707</math>
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Pokaż kod|Hide=Ukryj kod}}
 
<span style="font-size: 90%; color:black;">'''forstep'''(m=3, 10^8, 2, '''if'''( isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2)  &&  isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 3)  &&  !'''isprime'''(m), '''print'''("m=", m) ) )</span>
 
<br/>
 
{{\Spoiler}}
 
 
 
Widzimy, że prawdopodobieństwo błędnego rozpoznania pierwszości w&nbsp;przypadku liczb mniejszych od <math>10^8</math> dla podstaw <math>2</math> i <math>3</math> jest rzędu kilku milionowych. Gdyby prawdopodobieństwa błędnego rozpoznania pierwszości w&nbsp;przypadku podstaw <math>2</math> i <math>3</math> były niezależne, to spodziewalibyśmy się, że nie będzie wcale liczb mniejszych od <math>10^8</math> silnie pseudopierwszych jednocześnie względem podstaw <math>2</math> i <math>3</math>, bo prawdopodobieństwo takiego zdarzenia byłoby równe kilkudziesięciu bilonowym. Ale tak nie jest.
 
 
 
Jest to mocny argument za tym, że zastosowanie różnych (niezależnych) testów może być znacznie silniejszym narzędziem do testowania pierwszości liczb, niż wielokrotne stosowanie tego samego testu, gdzie poszczególne próby są tylko pozornie niezależne.
 
 
 
Połączenie znanych nam już testów prowadzi do prostego programu
 
 
 
<span style="font-size: 90%; color:black;">BPSWtest(m) =
 
{
 
'''forprime'''(p = 2, 1000, '''if'''( m % p > 0, '''next'''() ); '''if'''( m == p, '''return'''(1), '''return'''(0) ));
 
'''if'''( !isPrimeOr<span style="background-color: #fee481;">SPSP</span>(m, 2), '''return'''(0) );
 
'''if'''( !StrongLucasTest(m), '''return'''(0), '''return'''(1) );
 
}</span>
 
 
 
 
 
 
 
Funkcja <code>BPSWtest(m)</code> kolejno sprawdza:
 
 
 
:* czy liczba <math>m</math> jest podzielna przez niewielkie liczby pierwsze (w naszym przypadku mniejsze od <math>1000</math>); jeśli tak, to sprawdza, czy <math>m</math> jest liczbą pierwszą, czy złożoną i&nbsp;zwraca odpowiednio <math>1</math> lub <math>0</math>
 
:* czy liczba <math>m</math> przechodzi test Millera-Rabina dla podstawy <math>2</math>; jeśli nie, to zwraca <math>0</math>
 
:* czy liczba <math>m</math> przechodzi silny test Lucasa dla parametrów <math>P</math> i <math>Q</math>, które wybieramy metodą Selfridge'a; jeśli nie, to zwraca <math>0</math>, w&nbsp;przeciwnym wypadku zwraca <math>1</math>
 
 
 
 
 
Test w&nbsp;dokładnie takiej postaci zaproponowali Robert Baillie i&nbsp;Samuel Wagstaff<ref name="BaillieWagstaff1"/>. Nazwa testu to akronim, utworzony od pierwszych liter nazwisk Roberta Bailliego, Carla Pomerance'a, Johna Selfridge'a i&nbsp;Samuela Wagstaffa.
 
 
 
Nie jest znany żaden przykład liczby złożonej <math>m</math>, którą test BPSW<ref name="BPSW1"/><ref name="BPSW2"/> identyfikowałby jako pierwszą i&nbsp;z&nbsp;pewnością nie ma takich liczb dla <math>m < 2^{64} \approx 1.844 \cdot 10^{19}</math>. Warto przypomnieć: potrzebowaliśmy siedmiu testów Millera-Rabina (dla podstaw <math>2, 3, 5, 7, 11, 13, 17</math>), aby mieć pewność, że dowolna liczba <math>m < 3.41 \cdot 10^{14}</math> jest pierwsza (zobacz K22).
 
 
 
 
 
 
 
 
 
 
 
== Uzupełnienie ==
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L58</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą, to
 
 
 
::<math>\binom{p}{k} \equiv 0 \pmod{p}</math>
 
 
 
dla każdego <math>k \in [1, p - 1]</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Łatwo zauważamy, że dla <math>k \in [1, p - 1]</math> liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynnika dwumianowego
 
 
 
::<math>\binom{p}{k} = {\small\frac{p!}{k! \cdot (p - k)!}}</math>
 
 
 
zatem <math>p \biggr\rvert \binom{p}{k}</math>. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L59</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą nieparzystą, to
 
 
 
::<math>\binom{p + 1}{k} \equiv 0 \pmod{p}</math>
 
 
 
dla każdego <math>k \in [2, p - 1]</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Jeżeli <math>k \in [2, p - 1]</math>, to modulo <math>p</math> dostajemy
 
 
 
::<math>\binom{p + 1}{k} = \binom{p}{k} + \binom{p}{k - 1} \equiv 0 \pmod{p}</math>
 
 
 
Bo liczba pierwsza <math>p</math> dzieli licznik, ale nie dzieli mianownika współczynników dwumianowych po prawej stronie. Co należało pokazać.<br/>
 
&#9633;
 
{{\Spoiler}}
 
 
 
 
 
 
 
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L60</span><br/>
 
Jeżeli <math>p</math> jest liczbą pierwszą, to
 
 
 
::<math>\binom{p - 1}{k} \equiv (- 1)^k \pmod{p}</math>
 
 
 
dla każdego <math>k \in [0, p - 1]</math>.
 
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Łatwo sprawdzamy, że twierdzenie jest prawdziwe dla liczby pierwszej parzystej <math>p = 2</math>. Załóżmy, że <math>p</math> jest liczbą pierwszą nieparzystą. Równie łatwo sprawdzamy, że twierdzenie jest prawdziwe dla <math>k = 0</math> i <math>k = 1</math>. Zauważmy, że dla <math>k \in [1, p - 1]</math> jest
 
 
 
::<math>\binom{p - 1}{k} = {\small\frac{(p - 1) !}{k! (p - 1 - k) !}} = {\small\frac{p - k}{k}} \cdot {\small\frac{(p - 1) !}{(k - 1) ! (p - k) !}} = {\small\frac{p - k}{k}} \cdot \binom{p - 1}{k - 1} = {\small\frac{p}{k}} \cdot \binom{p - 1}{k - 1} - \binom{p - 1}{k - 1}</math>
 
 
 
Ponieważ współczynniki dwumianowe są liczbami całkowitymi, a&nbsp;liczba <math>k \in [2, p - 1]</math> nie dzieli liczby pierwszej nieparzystej <math>p</math>, to <math>k</math> musi dzielić liczbę <math>\binom{p - 1}{k - 1}</math>. Zatem dla <math>k \in [2, p - 1]</math> modulo <math>p</math> mamy
 
 
 
::<math>\binom{p - 1}{k} \equiv - \binom{p - 1}{k - 1}\pmod{p}</math>
 
 
 
Skąd otrzymujemy
 
 
 
::<math>\binom{p - 1}{k} \equiv (- 1)^1 \binom{p - 1}{k - 1} \equiv (- 1)^2 \binom{p - 1}{k - 2} \equiv \ldots \equiv (- 1)^{k - 2} \binom{p - 1}{2} \equiv (- 1)^{k - 1} \binom{p - 1}{1} \equiv (- 1)^k \pmod{p}</math>
 
  
 
Co należało pokazać.<br/>
 
Co należało pokazać.<br/>
Linia 2352: Linia 2001:
  
  
<span style="font-size: 110%; font-weight: bold;">Twierdzenie L61</span><br/>
 
Dla współczynników dwumianowych prawdziwe są następujące wzory
 
 
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
 
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
 
{{Spoiler|Style = font-style: italic; font-weight: bold; color: olive; text-decoration: underline;|Show=Dowód|Hide=Ukryj dowód}}
 
Ze wzoru dwumianowego
 
 
::<math>(a + b)^n = \sum_{k = 0}^{n} \binom{n}{k} a^{n - k} b^k</math>
 
 
z łatwością otrzymujemy
 
 
::<math>(1 + 1)^n = \sum_{k = 0}^{n} \binom{n}{k} = 2^n</math>
 
 
::<math>(1 - 1)^n = \sum_{k = 0}^{n} (- 1)^k \binom{n}{k} = 0</math>
 
 
Obliczając sumę i&nbsp;różnicę powyższych wzorów mamy
 
 
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 + (- 1)^k) = 2 \underset{k \; \text{parzyste}}{\sum^n_{k = 0}} \binom{n}{k} = 2^n</math>
 
 
::<math>\sum_{k = 0}^{n} \binom{n}{k} (1 - (- 1)^k) = 2 \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^n</math>
 
 
Skąd natychmiast wynika
 
 
::<math>\underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
  
::<math>\underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1}</math>
 
  
Co należało pokazać.<br/>
+
=== <span style="border-bottom:1px solid #000;">Funkcje <span style="font-size: 95%; background-color: #f8f9fa"><tt>digits(m, b)</tt></span> oraz <span style="font-size: 95%; background-color: #f8f9fa"><tt>issquare(m)</tt></span></span> ===
&#9633;
 
{{\Spoiler}}
 
  
 +
&nbsp;
  
 
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N47</span><br/>
<span style="font-size: 110%; font-weight: bold;">Uwaga L62</span><br/>
 
 
W funkcji <code>modLucas()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
 
W funkcji <code>modLucas()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
  
<code>digits(m, b)</code> - zwraca wektor cyfr liczby <math>| m |</math> w&nbsp;systemie liczbowym o&nbsp;podstawie <math>b</math>
+
<code>digits(m, b)</code> zwraca wektor cyfr liczby <math>| m |</math> w&nbsp;systemie liczbowym o&nbsp;podstawie <math>b</math>
  
 
W naszym przypadku potrzebowaliśmy uzyskać wektor cyfr liczby <math>m</math> w&nbsp;układzie dwójkowym, czyli funkcję <code>digits(m, 2)</code> . Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Zauważmy, że do zapisania liczby <math>m \geqslant 1</math> potrzebujemy <math>\log_2 m + 1</math> cyfr. Zastępując funkcję <math>\log_2 m</math> funkcją <math>\left \lfloor \tfrac{\log m}{\log 2} \right \rfloor</math> musimy liczyć się z&nbsp;możliwym błędem zaokrąglenia – dlatego w&nbsp;programie deklarujemy wektor <code>V</code> o&nbsp;długości <code>floor( log(m)/log(2) ) + 2</code>. Zwracany wektor <code>W</code> ma już prawidłową długość.
 
W naszym przypadku potrzebowaliśmy uzyskać wektor cyfr liczby <math>m</math> w&nbsp;układzie dwójkowym, czyli funkcję <code>digits(m, 2)</code> . Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Zauważmy, że do zapisania liczby <math>m \geqslant 1</math> potrzebujemy <math>\log_2 m + 1</math> cyfr. Zastępując funkcję <math>\log_2 m</math> funkcją <math>\left \lfloor \tfrac{\log m}{\log 2} \right \rfloor</math> musimy liczyć się z&nbsp;możliwym błędem zaokrąglenia – dlatego w&nbsp;programie deklarujemy wektor <code>V</code> o&nbsp;długości <code>floor( log(m)/log(2) ) + 2</code>. Zwracany wektor <code>W</code> ma już prawidłową długość.
Linia 2413: Linia 2032:
  
  
<span style="font-size: 110%; font-weight: bold;">Uwaga L63</span><br/>
+
<span style="font-size: 110%; font-weight: bold;">Uwaga N48</span><br/>
 
W funkcjach <code>LucasTest()</code> i <code>StrongLucasTest()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
 
W funkcjach <code>LucasTest()</code> i <code>StrongLucasTest()</code> wykorzystaliśmy zaimplementowaną w&nbsp;PARI/GP funkcję
  
<code>issquare(m)</code> - sprawdza, czy liczba <math>m</math> jest liczbą kwadratową
+
<code>issquare(m)</code> sprawdza, czy liczba <math>m</math> jest liczbą kwadratową
  
 
Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Potrzebna nam będzie funkcja, która znajduje całość z&nbsp;pierwiastka z&nbsp;liczby <math>m</math>, czyli <math>\left\lfloor \sqrt{m} \right\rfloor</math>. Wykorzystamy tutaj ciąg
 
Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Potrzebna nam będzie funkcja, która znajduje całość z&nbsp;pierwiastka z&nbsp;liczby <math>m</math>, czyli <math>\left\lfloor \sqrt{m} \right\rfloor</math>. Wykorzystamy tutaj ciąg
Linia 2423: Linia 2042:
 
   \begin{cases}
 
   \begin{cases}
 
   \qquad \;\; 1 & \text{gdy } k = 0 \\
 
   \qquad \;\; 1 & \text{gdy } k = 0 \\
       \tfrac{1}{2} \left( a_k + \tfrac{x}{a_k} \right) & \text{gdy } k > 0  
+
       \tfrac{1}{2} \left( a_k + \tfrac{x}{a_k} \right) & \text{gdy } k > 0 \\
 
   \end{cases}</math>
 
   \end{cases}</math>
  
Linia 2433: Linia 2052:
 
   \begin{cases}
 
   \begin{cases}
 
   \qquad \quad \; 1 & \text{gdy } k = 0 \\
 
   \qquad \quad \; 1 & \text{gdy } k = 0 \\
       \left\lfloor \tfrac{1}{2} \left( a_k + \left\lfloor \tfrac{m}{a_k} \right\rfloor \right) \right\rfloor & \text{gdy } k > 0  
+
       \left\lfloor \tfrac{1}{2} \left( a_k + \left\lfloor \tfrac{m}{a_k} \right\rfloor \right) \right\rfloor & \text{gdy } k > 0 \\
 
   \end{cases}</math>
 
   \end{cases}</math>
  
Linia 2471: Linia 2090:
  
 
<references>
 
<references>
 
<ref name="jacobi1">Wikipedia, ''Symbol Jacobiego'', ([https://pl.wikipedia.org/wiki/Symbol_Jacobiego Wiki-pl]), ([https://en.wikipedia.org/wiki/Jacobi_symbol Wiki-en])</ref>
 
 
<ref name="legendre1">Wikipedia, ''Symbol Legendre’a'', ([https://pl.wikipedia.org/wiki/Symbol_Legendre%E2%80%99a Wiki-pl]), ([https://en.wikipedia.org/wiki/Legendre_symbol Wiki-en])</ref>
 
 
<ref name="Norton1">Karl K. Norton, ''Numbers with Small Prime Factors, and the Least ''k''th Power Non-Residue'', Memoirs of the American Mathematical Society, No. 106 (1971)</ref>
 
 
<ref name="Trevino1">Enrique Treviño, ''The least k-th power non-residue'', Journal of Number Theory, Volume 149 (2015)</ref>
 
 
<ref name="Trevino2">Kevin J. McGown and Enrique Treviño, ''The least quadratic non-residue'', Mexican Mathematicians in the World (2021)</ref>
 
 
<ref name="Erdos1">Paul Erdős, ''Számelméleti megjegyzések I'', Afar. Lapok, v. 12 (1961)</ref>
 
  
 
<ref name="BaillieWagstaff1">Robert Baillie and Samuel S. Wagstaff Jr., ''Lucas Pseudoprimes'', Mathematics of Computation Vol. 35, No. 152 (1980), ([http://mpqs.free.fr/LucasPseudoprimes.pdf LINK])</ref>
 
<ref name="BaillieWagstaff1">Robert Baillie and Samuel S. Wagstaff Jr., ''Lucas Pseudoprimes'', Mathematics of Computation Vol. 35, No. 152 (1980), ([http://mpqs.free.fr/LucasPseudoprimes.pdf LINK])</ref>

Aktualna wersja na dzień 18:40, 17 mar 2024

11.01.2023



Ciągi Lucasa

Definicja N1
Niech [math]\displaystyle{ P, Q \in \mathbb{Z} \setminus \{0\} }[/math] oraz [math]\displaystyle{ D = P^2 - 4 Q \neq 0 }[/math]. Ciągi Lucasa [math]\displaystyle{ U_n = U_n (P, Q) }[/math] i [math]\displaystyle{ V_n = V_n (P, Q) }[/math] definiujemy następująco

[math]\displaystyle{ U_n = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} }[/math]
[math]\displaystyle{ V_n = \alpha^n + \beta^n }[/math]

gdzie liczby

[math]\displaystyle{ \alpha = {\small\frac{P + \sqrt{D}}{2}} }[/math]
[math]\displaystyle{ \beta = {\small\frac{P - \sqrt{D}}{2}} }[/math]

są pierwiastkami równania [math]\displaystyle{ x^2 - P x + Q = 0 }[/math].


Uwaga N2
Zauważmy, że:

[math]\displaystyle{ P = \alpha + \beta }[/math]
[math]\displaystyle{ Q = \alpha \beta }[/math]
[math]\displaystyle{ \sqrt{D} = \alpha - \beta }[/math]
[math]\displaystyle{ U_0 = 0 }[/math], [math]\displaystyle{ U_1 = 1 }[/math], [math]\displaystyle{ V_0 = 2 }[/math] i [math]\displaystyle{ V_1 = P }[/math]


Warunek [math]\displaystyle{ P^2 - 4 Q \neq 0 }[/math] wyklucza następujące pary [math]\displaystyle{ (P, Q) }[/math]

[math]\displaystyle{ (0, 0), (\pm 2, 1), (\pm 4, 4), (\pm 6, 9), (\pm 8, 16), (\pm 10, 25), (\pm 12, 36), ..., (\pm 2 n, n^2), ... }[/math]


Uwaga N3
Oczywiście liczby [math]\displaystyle{ \alpha }[/math] i [math]\displaystyle{ \beta }[/math] są również pierwiastkami równania

[math]\displaystyle{ x^{n + 2} - P x^{n + 1} + Q x^n = 0 }[/math]

Wynika stąd, że ciągi [math]\displaystyle{ (\alpha^n) }[/math] i [math]\displaystyle{ (\beta^n) }[/math] spełniają równania rekurencyjne

[math]\displaystyle{ \alpha^{n + 2} = P \alpha^{n + 1} - Q \alpha^n }[/math]
[math]\displaystyle{ \beta^{n + 2} = P \beta^{n + 1} - Q \beta^n }[/math]

Ciągi Lucasa [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] spełniają identyczne równania rekurencyjne jak ciągi [math]\displaystyle{ (\alpha^n) }[/math] i [math]\displaystyle{ (\beta^n) }[/math]. Istotnie, odejmując i dodając stronami wypisane powyżej równania, otrzymujemy

[math]\displaystyle{ U_{n + 2} = P U_{n + 1} - Q U_n }[/math]
[math]\displaystyle{ V_{n + 2} = P V_{n + 1} - Q V_n }[/math]

Dlatego możemy zdefiniować ciągi Lucasa [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] w sposób równoważny


Definicja N4
Niech [math]\displaystyle{ P, Q \in \mathbb{Z} \setminus \{0\} }[/math] oraz [math]\displaystyle{ D = P^2 - 4 Q \neq 0 }[/math]. Ciągi Lucasa [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] określone są następującymi wzorami rekurencyjnymi

[math]\displaystyle{ U_0 = 0 }[/math], [math]\displaystyle{ U_1 = 1 }[/math], [math]\displaystyle{ U_n = P U_{n - 1} - Q U_{n - 2} }[/math]
[math]\displaystyle{ V_0 = 2 }[/math], [math]\displaystyle{ V_1 = P }[/math], [math]\displaystyle{ V_n = P V_{n - 1} - Q V_{n - 2} }[/math]


Przykład N5
Początkowe wyrazy ciągów Lucasa


Uwaga N6
W PARI/GP możemy napisać prosty kod, który pozwoli obliczyć wartości wyrazów [math]\displaystyle{ U_n (P, Q) }[/math] i [math]\displaystyle{ V_n (P, Q) }[/math]

LucasU(n, P, Q) = if( n == 0, 0, if( n == 1, 1, P*LucasU(n-1, P, Q) - Q*LucasU(n-2, P, Q) ) )
LucasV(n, P, Q) = if( n == 0, 2, if( n == 1, P, P*LucasV(n-1, P, Q) - Q*LucasV(n-2, P, Q) ) )


Twierdzenie N7
Niech [math]\displaystyle{ D = P^2 - 4 Q }[/math]. Wyrazy ciągów Lucasa można przedstawić w postaci sumy

[math]\displaystyle{ 2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k }[/math]
[math]\displaystyle{ 2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k }[/math]
Dowód

Oznaczmy [math]\displaystyle{ \delta = \sqrt{D} }[/math], zatem [math]\displaystyle{ 2 \alpha = P + \delta }[/math] i [math]\displaystyle{ 2 \beta = P - \delta }[/math]. Ze wzoru dwumianowego, mamy

[math]\displaystyle{ 2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j }[/math]
[math]\displaystyle{ 2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j }[/math]

Obliczając sumę powyższych wzorów, otrzymujemy

[math]\displaystyle{ 2^n (\alpha^n + \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j + (- \delta)^j) }[/math]
[math]\displaystyle{ \quad \: = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} \cdot 2 \delta^{2 k} }[/math]
[math]\displaystyle{ \quad \: = 2 \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k }[/math]

gdzie [math]\displaystyle{ j = 2 k }[/math] i sumowanie przebiega od [math]\displaystyle{ k = 0 }[/math] do [math]\displaystyle{ k = \lfloor n / 2 \rfloor }[/math]

Zatem

[math]\displaystyle{ 2^{n - 1} V_n = \sum_{k = 0}^{\lfloor n / 2 \rfloor} \binom{n}{2 k} P^{n - 2 k} D^k }[/math]


Obliczając różnicę tych wzorów, mamy

[math]\displaystyle{ 2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) }[/math]
[math]\displaystyle{ \quad \: = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} \cdot 2 \delta^{2 k + 1} }[/math]
[math]\displaystyle{ \quad \: = 2 \delta \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k }[/math]

gdzie [math]\displaystyle{ j = 2 k + 1 }[/math] i sumowanie przebiega od [math]\displaystyle{ k = 0 }[/math] do [math]\displaystyle{ k = \lfloor (n - 1) / 2 \rfloor }[/math]


Zatem

[math]\displaystyle{ 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\sqrt{D}}} = 2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k }[/math]

Co należało pokazać.


Uwaga N8
Korzystając z twierdzenia N7, możemy napisać proste funkcje do znajdowania postaci kolejnych wyrazów [math]\displaystyle{ U_n (P, Q) }[/math] i [math]\displaystyle{ V_n (P, Q) }[/math]

U(n) = 2^(1 - n)*sum(k=0, floor((n-1)/2), binomial(n, 2*k+1) * P^(n-2*k-1) * (P^2-4*Q)^k)
V(n) = 2^(1 - n)*sum(k=0, floor(n/2), binomial(n, 2*k) * P^(n-2*k) * (P^2-4*Q)^k)


Często możemy spotkać założenie [math]\displaystyle{ P \geqslant 1 }[/math]. Poniższe twierdzenie wyjaśnia, dlaczego tak jest.

Twierdzenie N9
Jeżeli [math]\displaystyle{ (U_n) }[/math] i [math]\displaystyle{ (V_n) }[/math] są ciągami Lucasa, to

[math]\displaystyle{ U_n (- P, Q) = (- 1)^{n - 1} U_n (P, Q) }[/math]
[math]\displaystyle{ V_n (- P, Q) = (- 1)^n V_n (P, Q) }[/math]
Dowód

Niech

[math]\displaystyle{ \alpha = \frac{P + \sqrt{D}}{2} \qquad \qquad \;\; \beta = \frac{P - \sqrt{D}}{2} }[/math]
[math]\displaystyle{ a = \frac{- P + \sqrt{D}}{2} \qquad \qquad b = \frac{- P - \sqrt{D}}{2} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - P x + Q = 0 }[/math]
[math]\displaystyle{ x^2 + P x + Q = 0 }[/math]

Zatem definiują one ciągi Lucasa

[math]\displaystyle{ U_n (P, Q) = \frac{\alpha^n - \beta^n}{\alpha - \beta} \qquad \qquad \;\; V_n (P, Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (- P, Q) = \frac{a^n - b^n}{a - b} \qquad \qquad V_n (- P, Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = a - b = \sqrt{D} }[/math]
[math]\displaystyle{ \frac{a}{\beta} = \frac{b}{\alpha} = - 1 }[/math]

Łatwo znajdujemy

[math]\displaystyle{ U_n (- P, Q) = \frac{a^n - b^n}{a - b} = \frac{(- \beta)^n - (- \alpha)^n}{\sqrt{D}} = (- 1)^n \cdot \frac{\beta^n - \alpha^n}{\alpha - \beta} = (- 1)^{n - 1} \cdot U_n (P, Q) }[/math]
[math]\displaystyle{ V_n (- P, Q) = a^n + b^n = (- \beta)^n + (- \alpha)^n = (- 1)^n \cdot (\alpha^n + \beta^n) = (- 1)^n \cdot V_n (P, Q) }[/math]

Co należało pokazać.


Zadanie N10
Pokazać, że jeżeli [math]\displaystyle{ P, Q \in \mathbb{Z} \setminus \{ 0 \} }[/math] i [math]\displaystyle{ D = P^2 - 4 Q \neq 0 }[/math], to

[math]\displaystyle{ U_n (2 P, 4 Q) = 2^{n - 1} U_n (P, Q) }[/math]
[math]\displaystyle{ V_n (2 P, 4 Q) = 2^n V_n (P, Q) }[/math]
Rozwiązanie

Niech

[math]\displaystyle{ \alpha = {\small\frac{P + \sqrt{D}}{2}} \qquad \qquad \;\; \beta = {\small\frac{P - \sqrt{D}}{2}} }[/math]
[math]\displaystyle{ a = P + \sqrt{D} \qquad \qquad \;\; b = P - \sqrt{D} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - P x + Q = 0 }[/math]
[math]\displaystyle{ x^2 - 2 P x + 4 Q = 0 }[/math]

Zatem definiują one ciągi Lucasa

[math]\displaystyle{ U_n (P, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \;\;\; V_n (P, Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (2 P, 4 Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = \sqrt{D} }[/math]
[math]\displaystyle{ a - b = 2 \sqrt{D} }[/math]
[math]\displaystyle{ {\small\frac{a}{\alpha}} = {\small\frac{b}{\beta}} = 2 }[/math]

Łatwo znajdujemy

[math]\displaystyle{ U_n (2 P, 4 Q) = {\small\frac{a^n - b^n}{a - b}} = {\small\frac{(2 \alpha)^n - (2 \beta)^n}{2 \sqrt{D}}} = 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} = 2^{n - 1} U_n (P, Q) }[/math]
[math]\displaystyle{ V_n (2 P, 4 Q) = a^n + b^n = (2 \alpha)^n + (2 \beta)^n = 2^n (\alpha^n + \beta^n) = 2^n V_n (P, Q) }[/math]

Co należało pokazać.


Zadanie N11
Pokazać, że jeżeli [math]\displaystyle{ Q \in \mathbb{Z} \setminus \{ 0 \} }[/math] oraz [math]\displaystyle{ P = 4 Q - 1 }[/math], to

[math]\displaystyle{ U_{2 k} (P, P Q) = - (- P)^k U_{2 k} (1, Q) }[/math]
[math]\displaystyle{ U_{2 k + 1} (P, P Q) = (- P)^k V_{2 k + 1} (1, Q) }[/math]
[math]\displaystyle{ V_{2 k} (P, P Q) = (- P)^k V_{2 k} (1, Q) }[/math]
[math]\displaystyle{ V_{2 k + 1} (P, P Q) = - (- P)^{k + 1} U_{2 k + 1} (1, Q) }[/math]
Rozwiązanie

Niech

[math]\displaystyle{ \alpha = {\small\frac{1 + \sqrt{- P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{- P}}{2}} }[/math]
[math]\displaystyle{ a = {\small\frac{P + \sqrt{- P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{- P}}{2}} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - x + {\small\frac{P + 1}{4}} = 0 }[/math]
[math]\displaystyle{ x^2 - P x + {\small\frac{P (P + 1)}{4}} = 0 }[/math]

Z założenia [math]\displaystyle{ P = 4 Q - 1 }[/math], zatem

[math]\displaystyle{ x^2 - x + Q = 0 }[/math]
[math]\displaystyle{ x^2 - P x + P Q = 0 }[/math]

Czyli definiują one ciągi Lucasa

[math]\displaystyle{ U_n (1, Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad \:\:\: V_n (1, Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = a - b = \sqrt{- P} }[/math]
[math]\displaystyle{ {\small\frac{a}{\beta}} = {\small\frac{P + \sqrt{- P}}{1 - \sqrt{- P}}} = \sqrt{- P} }[/math]
[math]\displaystyle{ {\small\frac{b}{\alpha}} = {\small\frac{P - \sqrt{- P}}{1 + \sqrt{- P}}} = - \sqrt{- P} }[/math]


Łatwo znajdujemy

[math]\displaystyle{ U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k} - \left( - \alpha \sqrt{- P} \right)^{2 k}}{\sqrt{- P}} = \frac{(- P)^k (\beta^{2 k} - \alpha^{2 k})}{\alpha - \beta} = - (- P)^k U_{2 k} (1, Q) }[/math]


[math]\displaystyle{ U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \beta \sqrt{- P} \right)^{2 k + 1} - \left( - \alpha \sqrt{- P} \right)^{2 k + 1}}{\sqrt{- P}} = (- P)^k (\beta^{2 k + 1} + \alpha^{2 k + 1}) = (- P)^k V_{2 k + 1} (1, Q) }[/math]


[math]\displaystyle{ V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \beta \sqrt{- P} \right)^{2 k} + \left( - \alpha \sqrt{- P} \right)^{2 k} = (- P)^k (\alpha^{2 k} + \beta^{2 k}) = (- P)^k V_{2 k} (1, Q) }[/math]


[math]\displaystyle{ V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \beta \sqrt{- P} \right)^{2 k + 1} + \left( - \alpha \sqrt{- P} \right)^{2 k + 1} = (- P)^{k + 1} \cdot \frac{\beta^{2 k + 1} - \alpha^{2 k + 1}}{\sqrt{- P}} = - (- P)^{k + 1} U_{2 k + 1} (1, Q) }[/math]

Co należało pokazać.


Zadanie N12
Pokazać, że jeżeli [math]\displaystyle{ Q \in \mathbb{Z} \setminus \{ 0 \} }[/math] oraz [math]\displaystyle{ P = 4 Q + 1 }[/math], to

[math]\displaystyle{ U_{2 k} (P, P Q) = P^k U_{2 k} (1, - Q) }[/math]
[math]\displaystyle{ U_{2 k + 1} (P, P Q) = P^k V_{2 k + 1} (1, - Q) }[/math]
[math]\displaystyle{ V_{2 k} (P, P Q) = P^k V_{2 k} (1, - Q) }[/math]
[math]\displaystyle{ V_{2 k + 1} (P, P Q) = P^{k + 1} U_{2 k + 1} (1, - Q) }[/math]
Rozwiązanie

Niech

[math]\displaystyle{ \alpha = {\small\frac{1 + \sqrt{P}}{2}} \qquad \qquad \beta = {\small\frac{1 - \sqrt{P}}{2}} }[/math]
[math]\displaystyle{ a = {\small\frac{P + \sqrt{P}}{2}} \qquad \qquad b = {\small\frac{P - \sqrt{P}}{2}} }[/math]

Liczby [math]\displaystyle{ \alpha, \beta }[/math] oraz [math]\displaystyle{ a, b }[/math] są odpowiednio pierwiastkami równań

[math]\displaystyle{ x^2 - x - {\small\frac{P - 1}{4}} = 0 }[/math]
[math]\displaystyle{ x^2 - P x + {\small\frac{P (P - 1)}{4}} = 0 }[/math]

Z założenia [math]\displaystyle{ P = 4 Q + 1 }[/math], zatem

[math]\displaystyle{ x^2 - x - Q = 0 }[/math]
[math]\displaystyle{ x^2 - P x + P Q = 0 }[/math]

Czyli definiują one ciągi Lucasa

[math]\displaystyle{ U_n (1, - Q) = {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \qquad \qquad V_n (1, - Q) = \alpha^n + \beta^n }[/math]
[math]\displaystyle{ U_n (P, P Q) = {\small\frac{a^n - b^n}{a - b}} \qquad \qquad V_n (P, P Q) = a^n + b^n }[/math]

Zauważmy, że

[math]\displaystyle{ \alpha - \beta = a - b = \sqrt{P} }[/math]
[math]\displaystyle{ {\small\frac{a}{\alpha}} = {\small\frac{P + \sqrt{P}}{1 + \sqrt{P}}} = \sqrt{P} }[/math]
[math]\displaystyle{ {\small\frac{b}{\beta}} = {\small\frac{P - \sqrt{P}}{1 - \sqrt{P}}} = - \sqrt{P} }[/math]


Łatwo znajdujemy

[math]\displaystyle{ U_{2 k} (P, P Q) = \frac{a^{2 k} - b^{2 k}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k} - \left( - \beta \sqrt{P} \right)^{2 k}}{\sqrt{P}} = \frac{P^k (\alpha^{2 k} - \beta^{2 k})}{\alpha - \beta} = P^k U_{2 k} (1, - Q) }[/math]


[math]\displaystyle{ U_{2 k + 1} (P, P Q) = \frac{a^{2 k + 1} - b^{2 k + 1}}{a - b} = \frac{\left( \alpha \sqrt{P} \right)^{2 k + 1} - \left( - \beta \sqrt{P} \right)^{2 k + 1}}{\sqrt{P}} = P^k (\alpha^{2 k + 1} + \beta^{2 k + 1}) = P^k V_{2 k + 1} (1, - Q) }[/math]


[math]\displaystyle{ V_{2 k} (P, P Q) = a^{2 k} + b^{2 k} = \left( \alpha \sqrt{P} \right)^{2 k} + \left( - \beta \sqrt{P} \right)^{2 k} = P^k (\alpha^{2 k} + \beta^{2 k}) = P^k V_{2 k} (1, - Q) }[/math]


[math]\displaystyle{ V_{2 k + 1} (P, P Q) = a^{2 k + 1} + b^{2 k + 1} = \left( \alpha \sqrt{P} \right)^{2 k + 1} + \left( - \beta \sqrt{P} \right)^{2 k + 1} = P^{k + 1} \cdot \frac{\alpha^{2 k + 1} - \beta^{2 k + 1}}{\sqrt{P}} = P^{k + 1} U_{2 k + 1} (1, - Q) }[/math]

Co należało pokazać.


Twierdzenie N13
Dla wyrazów ciągów Lucasa prawdziwe są wzory

Dowód

Wzory 1. - 7. najłatwiej udowodnić korzystając z definicji N1.

Wzór 1.

[math]\displaystyle{ U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} - \alpha \beta \cdot {\small\frac{\alpha^{m - 1} - \beta^{m - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = U_m U_{n + 1} - Q U_{m - 1} U_n }[/math]


Wzór 2.

[math]\displaystyle{ V_{m + n} = \alpha^{m + n} + \beta^{m + n} }[/math]
[math]\displaystyle{ \quad \;\! = (\alpha^m + \beta^m) (\alpha^n + \beta^n) - \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n}) }[/math]
[math]\displaystyle{ \quad \;\! = V_m V_n - Q^n V_{m - n} }[/math]


Wzór 3.

[math]\displaystyle{ U_{m + n} = {\small\frac{\alpha^{m + n} - \beta^{m + n}}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = {\small\frac{(\alpha^m - \beta^m) (\alpha^n + \beta^n)}{\alpha - \beta}} - {\small\frac{\alpha^n \beta^n \cdot (\alpha^{m - n} - \beta^{m - n})}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \quad \: = U_m V_n - Q^n U_{m - n} }[/math]


Wzór 4.

[math]\displaystyle{ V_{m + n} = \alpha^{m + n} + \beta^{m + n} }[/math]
[math]\displaystyle{ \quad \;\! = (\alpha - \beta)^2 \cdot {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} + \alpha^n \beta^n \cdot (\alpha^{m - n} + \beta^{m - n}) }[/math]
[math]\displaystyle{ \quad \;\! = D U_m U_n + Q^n V_{m - n} }[/math]


Wzór 5.

[math]\displaystyle{ U_m V_n - V_m U_n = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} \cdot (\alpha^n + \beta^n) - (\alpha^m + \beta^m) \cdot {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \;\;\: = 2 \cdot \alpha^n \beta^n \cdot {\small\frac{\alpha^{m - n} - \beta^{m - n}}{\alpha - \beta}} }[/math]
[math]\displaystyle{ \;\;\: = 2 Q^n U_{m - n} }[/math]


Wzór 6.

[math]\displaystyle{ U^2_n = \left( {\small\frac{\alpha^n - \beta^n}{\alpha - \beta}} \right)^2 }[/math]
[math]\displaystyle{ \;\! = {\small\frac{\alpha^{n - 1} - \beta^{n - 1}}{\alpha - \beta}} \cdot {\small\frac{\alpha^{n + 1} - \beta^{n + 1}}{\alpha - \beta}} + \alpha^{n - 1} \beta^{n - 1} }[/math]
[math]\displaystyle{ \;\! = U_{n - 1} U_{n + 1} + Q^{n - 1} }[/math]


Wzór 7.

[math]\displaystyle{ V^2_n = (\alpha^n + \beta^n)^2 }[/math]
[math]\displaystyle{ \;\! = (\alpha^{n - 1} + \beta^{n - 1}) (\alpha^{n + 1} + \beta^{n + 1}) - (\alpha - \beta)^2 \cdot \alpha^{n - 1} \beta^{n - 1} }[/math]
[math]\displaystyle{ \;\! = V_{n - 1} V_{n + 1} - D Q^{n - 1} }[/math]


Wzory 8. - 18. można łatwo udowodnić, korzystając ze wzorów 1. - 7.

Wzór 8. Policzyć sumę wzoru 3. pomnożonego przez [math]\displaystyle{ 2 }[/math] i wzoru 5.

Wzór 9. Policzyć sumę wzorów 2. i 4.

Wzór 10. Połączyć wzory 2. i 4.

Wzór 11. We wzorze 3. położyć [math]\displaystyle{ m = n }[/math].

Wzór 12. We wzorze 2. położyć [math]\displaystyle{ m = n }[/math].

Wzór 13. We wzorze 4. położyć [math]\displaystyle{ m = n }[/math].

Wzór 14. We wzorze 10. położyć [math]\displaystyle{ m = n }[/math] lub połączyć wzory 12. i 13.

Wzór 15. We wzorze 9. położyć [math]\displaystyle{ m = 1 }[/math].

Wzór 16. We wzorze 8. położyć [math]\displaystyle{ m = 1 }[/math].

Wzór 17. We wzorze 15. położyć [math]\displaystyle{ V_{n + 1} = P V_n - Q V_{n - 1} }[/math].

Wzór 18. We wzorze 16. położyć [math]\displaystyle{ U_{n + 1} = P U_n - Q U_{n - 1} }[/math].


Wzory 19. - 21. to wzory, które wykorzystamy w przyszłości do szybkiego obliczania wartości wyrazów [math]\displaystyle{ U_n }[/math] i [math]\displaystyle{ V_n }[/math] modulo.

Wzór 19. Wystarczy połączyć wzory 11. oraz 16.

Wzór 20. Wystarczy we wzorze 1. położyć [math]\displaystyle{ m = n + 1 }[/math].

Wzór 21. Kładąc we wzorze 19. [math]\displaystyle{ n \rightarrow n + 1 }[/math], otrzymujemy

[math]\displaystyle{ U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - P U^2_{n + 1} \qquad (*) }[/math]

Kładąc we wzorze 1. [math]\displaystyle{ m = n + 2 }[/math], mamy

[math]\displaystyle{ U_{2 n + 2} = U_{n + 2} U_{n + 1} - Q U_{n + 1} U_n }[/math]

Czyli

[math]\displaystyle{ 2 U_{2 n + 2} = 2 U_{n + 1} U_{n + 2} - 2 Q U_n U_{n + 1} }[/math]

Odejmując od powyższego wzoru wzór [math]\displaystyle{ (*) }[/math], dostajemy wzór 21.

[math]\displaystyle{ U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1} }[/math]

Co należało pokazać.



Obliczanie wyrazów ciągu Lucasa modulo [math]\displaystyle{ m }[/math]

Przykład N14
Pokażemy, jak wykorzystać podane w twierdzeniu N13 wzory 19, 20, 21 i 16

[math]\displaystyle{ U_{2 n} = 2 U_n U_{n + 1} - P U^2_n }[/math]
[math]\displaystyle{ U_{2 n + 1} = U^2_{n + 1} - Q U^2_n }[/math]
[math]\displaystyle{ U_{2 n + 2} = P U^2_{n + 1} - 2 Q U_n U_{n + 1} }[/math]
[math]\displaystyle{ V_n = 2 U_{n + 1} - P U_n }[/math]

do szybkiego obliczania wyrazów ciągu Lucasa modulo [math]\displaystyle{ m }[/math].


Niech [math]\displaystyle{ P = 3 }[/math], [math]\displaystyle{ Q = 1 }[/math], [math]\displaystyle{ D = P^2 - 4 Q = 5 }[/math], [math]\displaystyle{ n = 22 = (10110)_2 = \sum_{j = 0}^{4} a_j \cdot 2^j }[/math].

W tabeli przedstawione są kolejne kroki, jakie musimy wykonać, aby policzyć [math]\displaystyle{ U_n = U_{22} }[/math] modulo [math]\displaystyle{ m = 23 }[/math].

W kolumnie [math]\displaystyle{ a_j }[/math] wypisujemy kolejne cyfry liczby [math]\displaystyle{ n = 22 = (10110)_2 }[/math] zapisanej w układzie dwójkowym. Liczby w kolumnie [math]\displaystyle{ k_j }[/math] tworzymy, biorąc kolejne (od prawej do lewej) cyfry liczby [math]\displaystyle{ n }[/math] w zapisie dwójkowym. Postępując w ten sposób, w ostatnim wierszu mamy [math]\displaystyle{ k_j = n }[/math] i wyliczamy liczby [math]\displaystyle{ U_n }[/math] i [math]\displaystyle{ U_{n + 1} }[/math] modulo [math]\displaystyle{ m }[/math].

Dla uproszczenia zapisu i ułatwienia zrozumienia liczbę [math]\displaystyle{ k_j }[/math] oznaczymy jako [math]\displaystyle{ r }[/math], a [math]\displaystyle{ k_{j + 1} }[/math] jako [math]\displaystyle{ s }[/math]. Zauważmy, że

  • tabela jest zbudowana tak, że musimy znaleźć wyrazy ciągu Lucasa o indeksie [math]\displaystyle{ r = k_j }[/math] oraz o indeksie o jeden większym: [math]\displaystyle{ r + 1 = k_j + 1 }[/math]
  • przejście do następnego wiersza (w dół) oznacza, że musimy znaleźć wyrazy o indeksie [math]\displaystyle{ s = k_{j + 1} }[/math] oraz o indeksie o jeden większym: [math]\displaystyle{ s + 1 }[/math]
  • przechodząc do następnego wiersza, dotychczasowa liczba [math]\displaystyle{ r = k_j }[/math] powiększa się o kolejną cyfrę ( [math]\displaystyle{ 0 }[/math] lub [math]\displaystyle{ 1 }[/math] ), którą dopisujemy z prawej strony
  • dodanie na końcu liczby [math]\displaystyle{ r = k_j }[/math] zera podwaja liczbę [math]\displaystyle{ r }[/math], czyli [math]\displaystyle{ s = k_{j + 1} = 2 r }[/math] oraz [math]\displaystyle{ s + 1 = 2 r + 1 }[/math]
  • dodanie na końcu liczby [math]\displaystyle{ r = k_j }[/math] jedynki podwaja liczbę [math]\displaystyle{ r }[/math] i zwiększą ją o jeden, czyli [math]\displaystyle{ s = k_{j + 1} = 2 r + 1 }[/math] oraz [math]\displaystyle{ s + 1 = 2 r + 2 }[/math]


Dlatego, jeżeli kolejną dodaną cyfrą jest zero, to korzystamy ze wzorów

[math]\displaystyle{ U_s = U_{2 r} = 2 U_r U_{r + 1} - P U^2_r }[/math]
[math]\displaystyle{ U_{s + 1} = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r }[/math]

Gdy kolejną dodaną cyfrą jest jeden, to stosujemy wzory

[math]\displaystyle{ U_s = U_{2 r + 1} = U^2_{r + 1} - Q U^2_r }[/math]
[math]\displaystyle{ U_{s + 1} = U_{2 r + 2} = P U^2_{r + 1} - 2 Q U_r U_{r + 1} }[/math]


Korzystając ze wzoru [math]\displaystyle{ V_n = 2 U_{n + 1} - P U_n }[/math], mamy

[math]\displaystyle{ V_{22} = 2 U_{23} - 3 U_{22} \equiv 44 - 60 \equiv - 16 \equiv 7 \pmod{23} }[/math]

Ostatecznie otrzymujemy

[math]\displaystyle{ U_{22} \equiv 20 \pmod{23} \quad }[/math] oraz [math]\displaystyle{ \quad V_{22} \equiv 7 \pmod{23} }[/math]


Uwaga N15
Uogólniając postępowanie przedstawione w przykładzie N14, możemy napisać program w PARI/GP do szybkiego obliczania wyrazów ciągu Lucasa [math]\displaystyle{ U_n (P, Q) }[/math] i [math]\displaystyle{ V_n (P, Q) }[/math] modulo [math]\displaystyle{ m }[/math].

modLucas(n, P, Q, m) =
{
local(A, i, s, U, U2, V, W, W2);
if( m == 1, return([0, 0]) );
if( n == 0, return([0, 2 % m]) );
A = digits(n, 2); \\ otrzymujemy wektor cyfr liczby n w układzie dwójkowym
s = length(A); \\ długość wektora A
U = 1;
W = P;
i = 1;
while( i++ <= s,
       if( A[i] == 0,  U2 = 2*U*W - P*U^2;  W2 = W^2 - Q*U^2 );
       if( A[i] == 1,  U2 = W^2 - Q*U^2;  W2 = P*W^2 - 2*Q*U*W );
       U = U2 % m;
       W = W2 % m;
     );
V = (2*W - P*U) % m;
return([U, V]);
}



Podzielność wyrazów [math]\displaystyle{ U_n (P, Q) }[/math] przez liczbę pierwszą nieparzystą

Uwaga N16
Niech [math]\displaystyle{ p }[/math] będzie liczbą pierwszą nieparzystą. W przypadku, gdy [math]\displaystyle{ p \nmid P Q }[/math] nie możemy nic powiedzieć o podzielności wyrazów [math]\displaystyle{ U_n }[/math] przez [math]\displaystyle{ p }[/math]. Przykładowo, jeżeli [math]\displaystyle{ P \equiv 1 \pmod{p} \; }[/math] [math]\displaystyle{ \text{i} \;\; Q \equiv 1 \pmod{p} }[/math], to modulo [math]\displaystyle{ p }[/math], mamy

[math]\displaystyle{ (U_n) \equiv (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, \ldots) }[/math]

W przypadku, gdy [math]\displaystyle{ P \equiv 2 \pmod{p} \; }[/math] [math]\displaystyle{ \text{i} \;\; Q \equiv 1 \pmod{p} }[/math], to modulo [math]\displaystyle{ p }[/math] mamy

[math]\displaystyle{ (U_n) \equiv (0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, 0, 1, 2, \ldots, p - 1, \ldots) }[/math]

Sytuacja wygląda inaczej, gdy [math]\displaystyle{ p \mid P Q }[/math].


Twierdzenie N17
Niech [math]\displaystyle{ p }[/math] będzie liczbą pierwszą nieparzystą.

●    jeżeli [math]\displaystyle{ \; p \mid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \mid Q , \; }[/math] to [math]\displaystyle{ \; p \mid U_n \; }[/math] dla [math]\displaystyle{ n \geqslant 2 }[/math]
●    jeżeli [math]\displaystyle{ \; p \mid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \nmid Q , \; }[/math] to [math]\displaystyle{ \; p \mid U_{2 n} \; }[/math] i [math]\displaystyle{ \; p \nmid U_{2 n + 1} }[/math]
●    jeżeli [math]\displaystyle{ \; p \nmid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \mid Q , \; }[/math] to [math]\displaystyle{ \; p \nmid U_n \; }[/math] dla [math]\displaystyle{ n \geqslant 1 }[/math]
●    jeżeli [math]\displaystyle{ \; p \mid Q , \; }[/math] to [math]\displaystyle{ \; p \mid U_n }[/math], gdzie [math]\displaystyle{ n \geqslant 2 }[/math], wtedy i tylko wtedy, gdy [math]\displaystyle{ \; p \mid P }[/math]
●    jeżeli [math]\displaystyle{ \; p \nmid P \; }[/math] [math]\displaystyle{ \text{i} \;\; p \mid D , \; }[/math] to [math]\displaystyle{ \; p \mid U_n \; }[/math] wtedy i tylko wtedy, gdy [math]\displaystyle{ p \mid n }[/math]

Założenie, że [math]\displaystyle{ p \nmid P }[/math] w ostatnim punkcie jest istotne. Gdy [math]\displaystyle{ \; p \mid P \; }[/math] i [math]\displaystyle{ \; p \mid D , \; }[/math] to [math]\displaystyle{ \; p \mid Q \; }[/math] i otrzymujemy punkt pierwszy.

Dowód

Punkt 1.

Ponieważ [math]\displaystyle{ U_2 = P }[/math], zatem [math]\displaystyle{ p \mid U_2 }[/math]. Dla [math]\displaystyle{ n \geqslant 3 }[/math] wyrażenie [math]\displaystyle{ U_n = P U_{n - 1} - Q U_{n - 2} }[/math] jest podzielne przez [math]\displaystyle{ p }[/math].

Punkt 2.

Indeksy parzyste. Indukcja matematyczna. Mamy [math]\displaystyle{ U_0 = 0 }[/math] i [math]\displaystyle{ U_2 = P }[/math], zatem [math]\displaystyle{ p \mid U_0 }[/math] i [math]\displaystyle{ p \mid U_2 }[/math]. Zakładając, że [math]\displaystyle{ p \mid U_{2 n} }[/math], z definicji ciągu [math]\displaystyle{ (U_k) }[/math], otrzymujemy dla [math]\displaystyle{ U_{2 n + 2} }[/math]

[math]\displaystyle{ U_{2 n + 2} = P U_{2 n - 1} - Q U_{2 n} }[/math]

Z założenia indukcyjnego wynika, że [math]\displaystyle{ p \mid U_{2 n + 2} }[/math], zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich [math]\displaystyle{ n \geqslant 0 }[/math].

Indeksy nieparzyste. Indukcja matematyczna. Mamy [math]\displaystyle{ U_1 = 1 }[/math] i [math]\displaystyle{ U_3 = P^2 - Q }[/math], zatem [math]\displaystyle{ p \nmid U_1 }[/math] i [math]\displaystyle{ p \nmid U_3 }[/math]. Zakładając, że [math]\displaystyle{ p \nmid U_{2 n - 1} }[/math], z definicji ciągu [math]\displaystyle{ (U_k) }[/math], otrzymujemy dla [math]\displaystyle{ U_{2 n + 1} }[/math]

[math]\displaystyle{ U_{2 n + 1} = P U_{2 n} - Q U_{2 n - 1} }[/math]

Z założenia indukcyjnego wynika, że [math]\displaystyle{ p \nmid U_{2 n + 1} }[/math], zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich [math]\displaystyle{ n \geqslant 1 }[/math].

Punkt 3.

Indukcja matematyczna. Mamy [math]\displaystyle{ U_1 = 1 }[/math] i [math]\displaystyle{ U_2 = P }[/math], zatem [math]\displaystyle{ p \nmid U_1 }[/math] i [math]\displaystyle{ p \nmid U_2 }[/math]. Zakładając, że [math]\displaystyle{ p \nmid U_n }[/math] zachodzi dla wszystkich liczb całkowitych dodatnich nie większych od [math]\displaystyle{ n }[/math], z definicji ciągu [math]\displaystyle{ (U_n) }[/math] otrzymujemy dla [math]\displaystyle{ n + 1 }[/math]

[math]\displaystyle{ U_{n + 1} = P U_n - Q U_{n - 1} }[/math]

Z założenia indukcyjnego wynika, że [math]\displaystyle{ p \nmid U_{n + 1} }[/math], zatem na mocy zasady indukcji matematycznej twierdzenie jest prawdziwe dla wszystkich liczb [math]\displaystyle{ n \geqslant 1 }[/math].

Punkt 4.

Wynika z punktów pierwszego i trzeciego.

Punkt 5.

Z twierdzenia N7 wiemy, że

[math]\displaystyle{ 2^{n - 1} U_n = \sum_{k = 0}^{\lfloor (n - 1) / 2 \rfloor} \binom{n}{2 k + 1} P^{n - 2 k - 1} D^k }[/math]
[math]\displaystyle{ \;\; = n P^{n - 1} + \binom{n}{3} P^{n - 3} D + \binom{n}{5} P^{n - 5} D^2 + \ldots + \begin{cases} n P D^{(n - 2) / 2} & \text{gdy }n\text{ jest parzyste} \\ D^{(n - 1) / 2} & \text{gdy }n\text{ jest nieparzyste} \\ \end{cases} }[/math]

Z założenia [math]\displaystyle{ p \mid D }[/math], zatem modulo [math]\displaystyle{ p }[/math] dostajemy

[math]\displaystyle{ 2^{n - 1} U_n \equiv n P^{n - 1} \pmod{p} }[/math]

Ponieważ [math]\displaystyle{ p \nmid P }[/math], zatem [math]\displaystyle{ p \mid U_n }[/math] wtedy i tylko wtedy, gdy [math]\displaystyle{ p \mid n }[/math]. Co należało pokazać.


Twierdzenie N18
Jeżeli [math]\displaystyle{ d }[/math] jest nieparzystym dzielnikiem [math]\displaystyle{ Q }[/math], to dla [math]\displaystyle{ n \geqslant 2 }[/math] jest

[math]\displaystyle{ U_n \equiv P^{n - 1} \pmod{d} }[/math]

W szczególności, gdy liczba pierwsza nieparzysta [math]\displaystyle{ p }[/math] jest dzielnikiem [math]\displaystyle{ Q }[/math] i [math]\displaystyle{ p \nmid P }[/math], to

[math]\displaystyle{ U_p \equiv 1 \pmod{p} }[/math]
Dowód

Oznaczmy [math]\displaystyle{ \delta = \sqrt{D} }[/math], zatem [math]\displaystyle{ 2 \alpha = P + \delta }[/math] i [math]\displaystyle{ 2 \beta = P - \delta }[/math]. Ze wzoru dwumianowego, mamy

[math]\displaystyle{ 2^n \alpha^n = (P + \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} \delta^j }[/math]
[math]\displaystyle{ 2^n \beta^n = (P - \delta)^n = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (- \delta)^j }[/math]


Obliczając różnicę wyjściowych wzorów, mamy

[math]\displaystyle{ 2^n (\alpha^n - \beta^n) = \sum_{j = 0}^{n} \binom{n}{j} P^{n - j} (\delta^j - (- \delta)^j) = }[/math]
[math]\displaystyle{ \quad \: = \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot 2 \delta^j }[/math]
[math]\displaystyle{ \quad \: = 2 \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot \delta \cdot D^{(j - 1) / 2} }[/math]

Rozpatrując powyższą równość modulo [math]\displaystyle{ Q }[/math] dostajemy (zobacz N43)

[math]\displaystyle{ 2^{n - 1} \cdot {\small\frac{\alpha^n - \beta^n}{\delta}} = 2^{n - 1} U_n \equiv \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} P^{n - j} \cdot P^{j - 1} }[/math]
[math]\displaystyle{ \;\:\: \equiv P^{n - 1} \underset{j \; \text{nieparzyste}}{\sum_{j = 1}^{n}} \binom{n}{j} }[/math]
[math]\displaystyle{ \;\:\: \equiv 2^{n - 1} P^{n - 1} }[/math]

Czyli

[math]\displaystyle{ 2^{n - 1} (U_n - P^{n - 1}) \equiv 0 \pmod{Q} }[/math]

Ponieważ [math]\displaystyle{ Q }[/math] dzieli [math]\displaystyle{ 2^{n - 1} (U_n - P^{n - 1}) }[/math], to tym bardziej [math]\displaystyle{ d }[/math] dzieli [math]\displaystyle{ 2^{n - 1} (U_n - P^{n - 1}) }[/math]. Z założenia [math]\displaystyle{ \gcd (d, 2^{n - 1}) = 1 }[/math], zatem [math]\displaystyle{ d }[/math] dzieli [math]\displaystyle{ U_n - P^{n - 1} }[/math] (zobacz C74).

W przypadku szczególnym, gdy [math]\displaystyle{ d = p }[/math], gdzie [math]\displaystyle{ p }[/math] jest nieparzystą liczbą pierwszą i [math]\displaystyle{ p \nmid P }[/math], z twierdzenia Fermata otrzymujemy natychmiast

[math]\displaystyle{ U_p \equiv P^{p - 1} \equiv 1 \pmod{p} }[/math]

Co należało pokazać.


Twierdzenie N19
Niech [math]\displaystyle{ D = P^2 - 4 Q }[/math], a [math]\displaystyle{ (D \mid p) }[/math] oznacza symbol Legendre'a, gdzie [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą i [math]\displaystyle{ p \nmid Q }[/math]. Mamy

●    [math]\displaystyle{ U_p \equiv (D \mid p) \pmod{p} }[/math]
●    jeżeli [math]\displaystyle{ (D \mid p) = - 1 , \; }[/math] to [math]\displaystyle{ \; p \mid U_{p + 1} }[/math]
●    jeżeli [math]\displaystyle{ (D \mid p) = 1 , \; }[/math] to [math]\displaystyle{ \; p \mid U_{p - 1} }[/math]
Dowód

Punkt 1.

Zauważmy, że przypadek gdy [math]\displaystyle{ p \mid Q }[/math], omówiliśmy w twierdzeniu poprzednim. Z założenia [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą. Z twierdzenia N7, w przypadku nieparzystego [math]\displaystyle{ n = p }[/math], otrzymujemy

[math]\displaystyle{ 2^{p - 1} U_p = p P^{p - 1} + \binom{p}{3} P^{p - 3} D + \binom{p}{5} P^{p - 5} D^2 + \ldots + \binom{p}{p-2} P^2 D^{(p - 3) / 2} + D^{(p - 1) / 2} }[/math]

Ponieważ dla każdego [math]\displaystyle{ k \in [1, p - 1] }[/math] (zobacz N43)

[math]\displaystyle{ \binom{p}{k} \equiv 0 \pmod{p} }[/math]

to modulo [math]\displaystyle{ p }[/math] dostajemy (zobacz J33)

[math]\displaystyle{ 2^{p - 1} U_p \equiv U_p \equiv D^{(p - 1) / 2} \equiv (D \mid p) \pmod{p} }[/math]

Punkt 2.

Zauważmy, że warunek [math]\displaystyle{ (D \mid p) = - 1 }[/math] nie może być spełniony, gdy [math]\displaystyle{ p \mid Q }[/math]. Istotnie, gdy [math]\displaystyle{ p \mid Q }[/math], to [math]\displaystyle{ D = P^2 - 4 Q \equiv P^2 \pmod{p} }[/math], czyli

[math]\displaystyle{ (D \mid p) = (P^2 \mid p) = (P \mid p)^2 = 0 , \; }[/math] gdy [math]\displaystyle{ p \mid P }[/math]

lub

[math]\displaystyle{ (D \mid p) = (P^2 \mid p) = (P \mid p)^2 = 1 , \; }[/math] gdy [math]\displaystyle{ p \nmid P }[/math]

i nie może być [math]\displaystyle{ (D \mid p) = - 1 }[/math].

Dla parzystego [math]\displaystyle{ n = p + 1 }[/math] otrzymujemy z twierdzenia N7

[math]\displaystyle{ 2^p U_{p + 1} = (p + 1) P^p + \binom{p + 1}{3} P^{p - 2} D + \binom{p + 1}{5} P^{p - 4} D^2 + \ldots + \binom{p + 1}{p - 2} P^3 D^{(p - 3) / 2} + (p + 1) P D^{(p - 1) / 2} }[/math]

Ponieważ dla [math]\displaystyle{ k \in [2, p - 1] }[/math] (zobacz N44)

[math]\displaystyle{ \binom{p + 1}{k} \equiv 0 \pmod{p} }[/math]

to modulo [math]\displaystyle{ p }[/math] dostajemy

[math]\displaystyle{ 2 U_{p + 1} \equiv P + P D^{(p - 1) / 2} \pmod{p} }[/math]


Z założenia [math]\displaystyle{ D }[/math] jest liczbą niekwadratową modulo [math]\displaystyle{ p }[/math], zatem [math]\displaystyle{ D^{(p - 1) / 2} \equiv - 1 \pmod{p} }[/math] (zobacz J31). Skąd wynika natychmiast, że

[math]\displaystyle{ 2 U_{p + 1} \equiv 0 \pmod{p} }[/math]

Czyli [math]\displaystyle{ p \mid U_{p + 1} }[/math].

Punkt 3.

Dla parzystego [math]\displaystyle{ n = p - 1 }[/math] otrzymujemy z twierdzenia N7

[math]\displaystyle{ 2^{p - 2} U_{p - 1} = (p - 1) P^{p - 2} + \binom{p - 1}{3} P^{p - 4} D + \binom{p - 1}{5} P^{p - 6} D^2 + \ldots + \binom{p - 1}{p - 4} P^3 D^{(p - 5) / 2} + (p - 1) P D^{(p - 3) / 2} }[/math]

Ponieważ dla [math]\displaystyle{ k \in [0, p - 1] }[/math] (zobacz N45)

[math]\displaystyle{ \binom{p - 1}{k} \equiv (- 1)^k \pmod{p} }[/math]

to modulo [math]\displaystyle{ p }[/math] mamy

[math]\displaystyle{ 2^{p - 2} U_{p - 1} \equiv - (P^{p - 2} + P^{p - 4} D + P^{p - 6} D^2 + \ldots + P D^{(p - 3) / 2}) \pmod{p} }[/math]
[math]\displaystyle{ \quad \,\, \equiv - P (P^{p - 3} + P^{p - 5} D + P^{p - 7} D^2 + \ldots + D^{(p - 3) / 2}) \pmod{p} }[/math]


Z założenia [math]\displaystyle{ D }[/math] jest liczbą kwadratową modulo [math]\displaystyle{ p }[/math] (zobacz J29), zatem istnieje taka liczba [math]\displaystyle{ R }[/math], że

[math]\displaystyle{ D \equiv R^2 \pmod{p} }[/math]

Ponieważ

  • [math]\displaystyle{ (D \mid p) = 1 }[/math], to [math]\displaystyle{ p \nmid D }[/math], zatem [math]\displaystyle{ p \nmid R }[/math]
  • z założenia [math]\displaystyle{ p \nmid Q }[/math], to [math]\displaystyle{ P^2 - R^2 \equiv P^2 - D \equiv 4 Q \not\equiv 0 \pmod{p} }[/math]


Czyli

[math]\displaystyle{ 2^{p - 2} U_{p - 1} \equiv - P (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p} }[/math]


Uwzględniając, że [math]\displaystyle{ P^2 - R^2 \not\equiv 0 \pmod{p} }[/math], możemy napisać

[math]\displaystyle{ 2^{p - 2} (P^2 - R^2) U_{p - 1} \equiv - P (P^2 - R^2) (P^{p - 3} + P^{p - 5} R^2 + P^{p - 7} R^4 + \ldots + R^{p - 3}) \pmod{p} }[/math]
[math]\displaystyle{ \equiv - P (P^{p - 1} - R^{p - 1}) \pmod{p} }[/math]
[math]\displaystyle{ \equiv 0 \pmod{p} }[/math]

Zauważmy, że wynik nie zależy od tego, czy [math]\displaystyle{ p \mid P }[/math], czy [math]\displaystyle{ p \nmid P }[/math]. Skąd wynika

[math]\displaystyle{ U_{p - 1} \equiv 0 \pmod{p} }[/math]

Co należało pokazać.


Aby zapisać punkty 2. i 3. twierdzenia N19 (i tylko te punkty) w zwartej formie, musimy założyć, że [math]\displaystyle{ \gcd (p, D) = 1 }[/math]. Otrzymujemy
Twierdzenie N20
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą i [math]\displaystyle{ \gcd (p, Q D) = 1 }[/math], to

[math]\displaystyle{ U_{p - (D \mid p)} \equiv 0 \pmod{p} }[/math]



Liczby pseudopierwsze Lucasa

Uwaga N21
Z twierdzenia N20 wiemy, że liczby pierwsze nieparzyste [math]\displaystyle{ p }[/math] takie, że [math]\displaystyle{ p \nmid Q D }[/math] są dzielnikami wyrazów ciągu Lucasa [math]\displaystyle{ U_{p - (D \mid p)} }[/math], gdzie [math]\displaystyle{ (D \mid p) }[/math] oznacza symbol Legendre'a. Jeśli zastąpimy symbol Legendre'a symbolem Jacobiego, to będziemy mogli badać prawdziwość tego twierdzenia dla liczb złożonych i łatwo przekonamy się, że dla pewnych liczb złożonych [math]\displaystyle{ m }[/math] kongruencja

[math]\displaystyle{ U_{m - (D \mid m)} \equiv 0 \pmod{m} }[/math]

również jest prawdziwa. Prowadzi to definicji liczb pseudopierwszych Lucasa.


Definicja N22
Powiemy, że liczba złożona nieparzysta [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Lucasa dla parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math] (symbolicznie: LPSP( [math]\displaystyle{ P, Q }[/math] )), jeżeli [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math] i

[math]\displaystyle{ U_{m - (D \mid m)} \equiv 0 \pmod{m} }[/math]

gdzie [math]\displaystyle{ (D \mid m) }[/math] oznacza symbol Jacobiego.


Twierdzenie N23
Jeżeli liczba złożona nieparzysta [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Lucasa dla parametrów [math]\displaystyle{ P = a + 1 }[/math] i [math]\displaystyle{ Q = a }[/math], gdzie [math]\displaystyle{ a \geqslant 2 }[/math], to jest liczbą pseudopierwszą Fermata przy podstawie [math]\displaystyle{ a }[/math].

Dowód

Połóżmy we wzorze definiującym ciąg Lucasa

[math]\displaystyle{ U_m = {\small\frac{\alpha^m - \beta^m}{\alpha - \beta}} }[/math]

[math]\displaystyle{ \alpha = a }[/math] i [math]\displaystyle{ \beta = 1 }[/math]. Odpowiada to parametrom [math]\displaystyle{ P = \alpha + \beta = a + 1 }[/math], [math]\displaystyle{ Q = \alpha \beta = a }[/math], [math]\displaystyle{ D = (\alpha - \beta)^2 = (a - 1)^2 }[/math].

Ponieważ musi być [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math], to mamy [math]\displaystyle{ \gcd (m, (a - 1) a) = 1 }[/math] i wynika stąd, że [math]\displaystyle{ (D \mid m) = 1 }[/math]. Z założenia [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Lucasa dla parametrów [math]\displaystyle{ P = a + 1 }[/math] i [math]\displaystyle{ Q = a }[/math], zatem

[math]\displaystyle{ U_{m - 1} (a + 1, a) \equiv 0 \pmod{m} }[/math]

Czyli

[math]\displaystyle{ {\small\frac{a^{m - 1} - 1}{a - 1}} \equiv 0 \pmod{m} }[/math]

Jeżeli [math]\displaystyle{ m \biggr\rvert {\small\frac{a^{m - 1} - 1}{a - 1}} }[/math], to tym bardziej [math]\displaystyle{ m \big\rvert (a^{m - 1} - 1) }[/math] i możemy napisać

[math]\displaystyle{ a^{m - 1} - 1 \equiv 0 \pmod{m} }[/math]

Zatem [math]\displaystyle{ m }[/math] jest liczbą pseudopierwszą Fermata przy podstawie [math]\displaystyle{ a }[/math]. Co należało pokazać.


Uwaga N24
Wykorzystując funkcje jacobi(a, n) i modLucas(n, P, Q, m) (zobacz J48, N15) możemy napisać prosty program, który sprawdza, czy dla liczby nieparzystej [math]\displaystyle{ m }[/math] prawdziwe jest twierdzenie N20.

isPrimeOrLPSP(m, P, Q) = 
{
local(D, js);
D = P^2 - 4*Q;
if( gcd(m, 2*Q*D) > 1, return(0) );
js = jacobi(D, m);
if( modLucas(m - js, P, Q, m)[1] == 0, return(1), return(0) );
}


Przykład N25
Poniższa tabela zawiera najmniejsze liczby pseudopierwsze Lucasa dla różnych parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]

Pokaż kod
FirstLPSP(Stop) = 
\\ najmniejsze LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, 
                  print("Q= ", Q, "   P= ", P, "   ------------------");
                  next();
                );
              m = 3;
              while( m < Stop,
                     if( isPrimeOrLPSP(m, P, Q)  &&  !isprime(m),
                         print("Q= ", Q, "   P= ", P, "   m= ", m, "   (D|m)= ", jacobi(D, m));
                         break();
                       );
                     m = m + 2;
                   );
            );
     );
}


Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których [math]\displaystyle{ (D \mid m) = - 1 }[/math].


Przykład N26
Ilość liczb LPSP([math]\displaystyle{ P, Q }[/math]) mniejszych od [math]\displaystyle{ 10^9 }[/math]

Pokaż kod
NumOfLPSP(Stop) = 
\\ ilość liczb pseudopierwszych Lucasa LPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, print("Q= ", Q, "   P= ", P, "   ------------------"); next() );
              s = 0;
              m = 3;
              while( m < Stop,
                     if( isPrimeOrLPSP(m, P, Q)  &&  !isprime(m), s++ );
                     m = m + 2;
                   );
              print("Q= ", Q, "   P= ", P, "   s= ", s);
            );
     );
}



Uwaga N27
Dla [math]\displaystyle{ (P, Q) = (1, 1) }[/math] ciąg Lucasa [math]\displaystyle{ (U_n) }[/math] ma postać

[math]\displaystyle{ (U_n) = (0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, 1, \ldots) }[/math]

Stosując indukcję matematyczną, udowodnimy, że [math]\displaystyle{ U_{3 k} = 0 }[/math]. Łatwo sprawdzamy, że dla [math]\displaystyle{ k = 0 }[/math] i [math]\displaystyle{ k = 1 }[/math] wzór jest prawdziwy. Zakładając prawdziwość wzoru dla wszystkich liczb naturalnych nie większych od [math]\displaystyle{ k }[/math], otrzymujemy dla [math]\displaystyle{ k + 1 }[/math] (zobacz N13 p.3)

[math]\displaystyle{ U_{3 (k + 1)} = U_{3 k + 3} = U_{3 k} V_3 - U_{3 (k - 1)} = 0 }[/math]

Co kończy dowód. Zbadajmy liczby pseudopierwsze Lucasa dla [math]\displaystyle{ (P, Q) = (1, 1) }[/math].

Mamy [math]\displaystyle{ D = P^2 - 4 Q = - 3 }[/math]. Wynika stąd, że nie może być [math]\displaystyle{ 3 \mid m }[/math], bo mielibyśmy [math]\displaystyle{ \gcd (m, Q D) = 3 \gt 1 }[/math].

Z zadania J46 wiemy, że

[math]\displaystyle{ (- 3 \mid m) = \begin{cases} \;\;\: 1 & \text{gdy } m = 6 k + 1 \\ \;\;\: 0 & \text{gdy } m = 6 k + 3 \\ - 1 & \text{gdy } m = 6 k + 5 \\ \end{cases} }[/math]

Ponieważ [math]\displaystyle{ 3 \nmid m }[/math], to wystarczy zbadać przypadki [math]\displaystyle{ m = 6 k + 1 }[/math] i [math]\displaystyle{ m = 6 k + 5 }[/math]. W pierwszym przypadku jest

[math]\displaystyle{ U_{m - (- 3 \mid m)} = U_{6 k + 1 - 1} = U_{6 k} = 0 }[/math]

W drugim przypadku, gdy [math]\displaystyle{ m = 6 k + 5 }[/math], dostajemy

[math]\displaystyle{ U_{m - (- 3 \mid m)} = U_{6 k + 5 + 1} = U_{6 (k + 1)} = 0 }[/math]

Zatem dla dowolnej liczby nieparzystej [math]\displaystyle{ m }[/math] niepodzielnej przez [math]\displaystyle{ 3 }[/math] jest

[math]\displaystyle{ U_{m - (- 3 \mid m)} \equiv 0 \pmod{m} }[/math]

Czyli liczbami pseudopierwszymi Lucasa dla parametrów [math]\displaystyle{ (P, Q) = (1, 1) }[/math] będą liczby nieparzyste [math]\displaystyle{ m }[/math], które nie są podzielne przez [math]\displaystyle{ 3 }[/math] i nie są liczbami pierwszymi. Ilość takich liczb nie większych od [math]\displaystyle{ 10^k }[/math] możemy łatwo znaleźć poleceniem

for(k = 1, 9, s = 0; forstep(m = 3, 10^k, 2, if( m%6 <> 3, s = s + !isprime(m) )); print(s))


Zadanie N28
Pokazać, że ilość liczb pseudopierwszych Lucasa dla parametrów [math]\displaystyle{ (P, Q) = (2, 2) }[/math] nie większych od [math]\displaystyle{ 10^k }[/math] możemy znaleźć poleceniem

for(k = 1, 9, s = 0; forstep(m = 3, 10^k, 2, s = s + !isprime(m)); print(s))



Metoda Selfridge'a wyboru parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]

Uwaga N29
Twierdzenie N20 możemy wykorzystać do testowania pierwszości liczb. Ponieważ musi być spełniony warunek [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math], to nie każda para liczb [math]\displaystyle{ P, Q }[/math] (np. wybrana losowo) nadaje się do przeprowadzenia testu. Zawsze będziemy zmuszeni określić zasadę postępowania, która doprowadzi do wyboru właściwej pary [math]\displaystyle{ P, Q }[/math].

Robert Baillie i Samuel Wagstaff przedstawili[1] dwie metody wyboru parametrów dla testu Lucasa. Ograniczymy się do omówienia tylko pierwszej z nich (metodę zaproponował John Selfridge).

Rozważmy ciąg [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math], gdzie [math]\displaystyle{ k \geqslant 2 }[/math], czyli [math]\displaystyle{ a_k = (5, - 7, 9, - 11, 13, - 15, \ldots) }[/math]. Niech [math]\displaystyle{ D }[/math] będzie pierwszym wyrazem ciągu [math]\displaystyle{ (a_k) }[/math], dla którego jest [math]\displaystyle{ (a_k \mid m) = - 1 }[/math]. Dla tak ustalonego [math]\displaystyle{ D }[/math] przyjmujemy [math]\displaystyle{ P = 1 }[/math] i [math]\displaystyle{ Q = (1 - D) / 4 }[/math].

Tabela przedstawia początkowe wartości [math]\displaystyle{ Q }[/math], jakie otrzymamy, stosując tę metodę.


Zauważmy, że

  • jeżeli liczba nieparzysta [math]\displaystyle{ m }[/math] jest liczbą kwadratową, to wybór [math]\displaystyle{ D }[/math] nie będzie możliwy
  • w przypadku zastosowania tej metody znajdziemy tylko liczby pierwsze lub pseudopierwsze Lucasa, które spełniają kongruencję [math]\displaystyle{ U_{m + 1} \equiv 0 \pmod{m} }[/math], czyli tylko część liczb pseudopierwszych Lucasa określonych w definicji N22


Ponieważ Baillie i Wagstaff określili metodę zaproponowaną przez Selfridge'a jako metodę A, to pozostaniemy przy tej nazwie. Korzystając ze wzoru rekurencyjnego

[math]\displaystyle{ a_{k+1} = \begin{cases} \qquad \qquad 5 & \text{gdy } k = 1 \\ - a_k - 2 * \mathop{\textnormal{sign}}( a_k ) & \text{gdy } k \geqslant 2 \\ \end{cases} }[/math]

możemy łatwo napisać odpowiednią funkcję znajdującą liczby [math]\displaystyle{ P, Q }[/math] według tej metody.

MethodA(m) = 
{
local(a, js);
a = 5;
while( 1,
       js = jacobi(a, m);
       if( js == 0  &&  a % m <> 0, return([0, 0]) );
       if( js == -1, return([1, (1 - a)/4]) );
       a = -a - 2*sign(a);
     );
}

Wyjaśnienia wymaga druga linia kodu w pętli while. Wiemy, że (zobacz J42)

[math]\displaystyle{ (a \mid m) = 0 \quad \qquad \Longleftrightarrow \quad \qquad \gcd (a, m) \gt 1 }[/math]

Jednak z faktu, że [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] nie wynika natychmiast, że liczba [math]\displaystyle{ m }[/math] jest liczbą złożoną. Rozważmy dwa przypadki: gdy [math]\displaystyle{ m \mid a }[/math] i [math]\displaystyle{ m \nmid a }[/math].

Gdy [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] i [math]\displaystyle{ m \mid a }[/math], to [math]\displaystyle{ \gcd (a, m) = \gcd (k \cdot m, m) = m \gt 1 }[/math] i nie jesteśmy w stanie rozstrzygnąć, czy liczba [math]\displaystyle{ m }[/math] jest liczbą pierwszą, czy złożoną. Widać to dobrze na prostych przykładach

[math]\displaystyle{ \gcd (7, 7) = \gcd (14, 7) = 7 \gt 1 }[/math]
[math]\displaystyle{ \gcd (15, 15) = \gcd (30, 15) = 15 \gt 1 }[/math]

Gdy [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] i [math]\displaystyle{ m \nmid a }[/math], to [math]\displaystyle{ m }[/math] jest liczbą złożoną. Ponieważ [math]\displaystyle{ m \nmid a }[/math], to [math]\displaystyle{ a = k \cdot m + r }[/math], gdzie [math]\displaystyle{ r \in [1, m - 1] }[/math]. Mamy

[math]\displaystyle{ \gcd (a, m) = \gcd (k \cdot m + r, m) = \gcd (r, m) = d }[/math]

Musi być [math]\displaystyle{ d \gt 1 }[/math], bo założyliśmy, że [math]\displaystyle{ \gcd (a, m) \gt 1 }[/math] i musi być [math]\displaystyle{ d \lt m }[/math], bo [math]\displaystyle{ d \leqslant r \leqslant m - 1 }[/math]. Zatem [math]\displaystyle{ d }[/math] jest dzielnikiem nietrywialnym liczby [math]\displaystyle{ m }[/math] i [math]\displaystyle{ m }[/math] jest liczbą złożoną.

Omawiana linia kodu zapewnia wysłanie informacji o tym, że liczba [math]\displaystyle{ m }[/math] jest liczbą złożoną (zwrot wektora [0, 0]). W przypadku, gdy nie mamy takiej pewności, kontynuujemy szukanie liczby [math]\displaystyle{ a }[/math], takiej że [math]\displaystyle{ (a \mid m) = - 1 }[/math], pozostawiając zbadanie pierwszości liczby [math]\displaystyle{ m }[/math] na kolejnym etapie testowania.


Uważny Czytelnik dostrzeże, że nie zbadaliśmy, czy spełniony jest warunek [math]\displaystyle{ \gcd (m, Q) = 1 }[/math]. Nie musimy tego robić, bo zwracana przez funkcję MethodA() liczba [math]\displaystyle{ Q }[/math] jest względnie pierwsza z [math]\displaystyle{ m }[/math]. Omówimy ten problem dokładnie w zadaniu N30. Poniżej pokażemy, że nawet gdyby było [math]\displaystyle{ \gcd (m, Q) \gt 1 }[/math], to złożona liczba [math]\displaystyle{ m }[/math] nie zostanie uznana za liczbę pseudopierwszą Lucasa.

Zauważmy, że jeżeli [math]\displaystyle{ m }[/math] jest liczbą złożoną i ma dzielnik pierwszy [math]\displaystyle{ p \lt m }[/math], który dzieli [math]\displaystyle{ Q }[/math], to [math]\displaystyle{ p \mid Q }[/math] i [math]\displaystyle{ p \nmid P }[/math] (bo [math]\displaystyle{ P = 1 }[/math]), zatem [math]\displaystyle{ p \nmid U_k }[/math] dla [math]\displaystyle{ k \geqslant 1 }[/math] (zobacz N17), czyli nie może być

[math]\displaystyle{ U_{m + 1} (1, Q) \equiv 0 \pmod{m} }[/math]

bo mielibyśmy

[math]\displaystyle{ U_{m + 1} (1, Q) \equiv 0 \pmod{p} }[/math]

a to jest niemożliwe. Zatem program wykorzystujący twierdzenie N20 wykryje złożoność liczby [math]\displaystyle{ m }[/math].

Łatwo pokażemy, że nie jest możliwe, aby liczba [math]\displaystyle{ m }[/math] była liczbą pierwszą i była dzielnikiem [math]\displaystyle{ Q }[/math]. Jeżeli [math]\displaystyle{ m }[/math] jest liczbą pierwszą, to istnieje dokładnie [math]\displaystyle{ \tfrac{m - 1}{2} }[/math] liczb kwadratowych modulo [math]\displaystyle{ p }[/math] i [math]\displaystyle{ \tfrac{m - 1}{2} }[/math] liczb niekwadratowych modulo [math]\displaystyle{ p }[/math], zatem rozpoczynając od wyrazu [math]\displaystyle{ a_2 }[/math] możemy dojść co najwyżej do wyrazu o indeksie [math]\displaystyle{ k = \tfrac{m - 1}{2} + 2 }[/math], czyli

[math]\displaystyle{ | a_k | \leqslant m + 4 }[/math]

Skąd wynika, że

[math]\displaystyle{ | Q | = \left| {\small\frac{1 - a_k}{4}} \right| \leqslant {\small\frac{m + 5}{4}} \lt m }[/math]

Ostatnia nierówność jest prawdziwa dla [math]\displaystyle{ m \gt {\small\frac{5}{3}} }[/math], czyli dla wszystkich liczb pierwszych. Ponieważ [math]\displaystyle{ | Q | \lt m }[/math], w przypadku gdy [math]\displaystyle{ m }[/math] jest liczbą pierwszą, to [math]\displaystyle{ m }[/math] nie może być dzielnikiem liczby [math]\displaystyle{ Q }[/math].


Zadanie N30
Pokazać, że w przypadku, gdy dla kolejnych liczb [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math] sprawdzamy, czy konsekwencją [math]\displaystyle{ (a_k \mid m) = 0 }[/math] jest złożoność liczby [math]\displaystyle{ m }[/math], to dla każdej liczby [math]\displaystyle{ Q }[/math] wyznaczonej metodą Selfridge'a jest [math]\displaystyle{ \gcd (Q, m) = 1 }[/math].

Rozwiązanie

Niech [math]\displaystyle{ m = 21 }[/math]. Rozpoczniemy od przykładu liczb [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math] dla [math]\displaystyle{ k = 0, 1, \ldots, m - 1 }[/math].

Zauważmy, że modulo [math]\displaystyle{ 21 }[/math] ciąg [math]\displaystyle{ (a_k) = (1, - 3, 5, - 7, \ldots, 37, - 39, 41) }[/math] jest identyczny z ciągiem [math]\displaystyle{ (0, 1, 2, \ldots, 19, 20) }[/math], a ciąg [math]\displaystyle{ (| a_k |) }[/math] to kolejne liczby nieparzyste od [math]\displaystyle{ 1 }[/math] do [math]\displaystyle{ 2 m - 1 }[/math].


Poniżej pokażemy, dlaczego musi być [math]\displaystyle{ \gcd (Q, m) = 1 }[/math], gdzie [math]\displaystyle{ Q }[/math] jest liczbą wyznaczoną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby [math]\displaystyle{ m }[/math] przy testowaniu kolejnych liczb [math]\displaystyle{ a_k }[/math]). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby [math]\displaystyle{ m }[/math]. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość [math]\displaystyle{ Q }[/math] na podstawie innego wyrazu ciągu [math]\displaystyle{ a_k }[/math] (ten symbol Jacobiego został zapisany zwykłą czcionką).

[math]\displaystyle{ m = 3 , \;\; (5 \mid 3) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 5 , \;\; (5 \mid 5) = 0 , \;\; (- 7 \mid 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 \;\; }[/math] (zauważmy, że [math]\displaystyle{ (5 \mid 5) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 7 , \;\; (5 \mid 7) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 9 , \;\; }[/math] (liczba kwadratowa)
[math]\displaystyle{ m = 11 , \;\; (- 11 \mid 11) = 0 , \;\; (13 \mid 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\; }[/math] (zauważmy, że [math]\displaystyle{ (- 11 \mid 11) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 13 , \;\; (5 \mid 13) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 15 , \;\; \boldsymbol{(5 \mid 15) = 0} , \;\; (13 \mid 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)
[math]\displaystyle{ m = 17 , \;\; (5 \mid 17) = - 1 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 19 , \;\; (- 7 \mid 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 21 , \;\; \boldsymbol{(- 7 \mid 21) = 0} , \;\; (- 11 \mid 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)


Niech [math]\displaystyle{ m \geqslant 23 }[/math]. Wiemy, że w ciągu [math]\displaystyle{ (5, - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1) }[/math] wystąpią liczby [math]\displaystyle{ a_k }[/math] takie, że [math]\displaystyle{ (a_k \mid m) = - 1 }[/math]. Warunek [math]\displaystyle{ (a_k \mid m) = 0 }[/math] oznacza, że [math]\displaystyle{ (2 k + 1 \mid m) = 0 }[/math], bo

[math]\displaystyle{ (a_k \mid m) = ((- 1)^k (2 k + 1) \mid m) = ((- 1)^k \mid m) \cdot (2 k + 1 \mid m) = (- 1 \mid m)^k \cdot (2 k + 1 \mid m) = \pm (2 k + 1 \mid m) }[/math]

Jeżeli będą spełnione warunki [math]\displaystyle{ (a_k \mid m) = 0 }[/math] i [math]\displaystyle{ R_m (a_k) \neq 0 }[/math], to liczba [math]\displaystyle{ m }[/math] będzie liczbą złożoną.

Wypiszmy kolejne próby dla [math]\displaystyle{ m \geqslant 23 }[/math]. Liczba [math]\displaystyle{ r }[/math] jest numerem próby.

[math]\displaystyle{ r = 1 , \;\; a_{r + 1} = 5 }[/math]
●    [math]\displaystyle{ (5 \mid m) = 1 }[/math] [math]\displaystyle{ 5 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (5 \mid m) = 0 }[/math] [math]\displaystyle{ 5 \mid m }[/math] koniec
●    [math]\displaystyle{ (5 \mid m) = - 1 \quad }[/math] [math]\displaystyle{ 5 \nmid m }[/math] [math]\displaystyle{ D = 5 , \;\; Q = - 1 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec
[math]\displaystyle{ r = 2 , \;\; a_{r + 1} = - 7 }[/math]
●    [math]\displaystyle{ (- 7 \mid m) = 1 }[/math] [math]\displaystyle{ 7 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 7 \mid m) = 0 }[/math] [math]\displaystyle{ 7 \mid m }[/math] koniec
●    [math]\displaystyle{ (- 7 \mid m) = - 1 \quad }[/math] [math]\displaystyle{ 7 \nmid m }[/math] [math]\displaystyle{ D = -7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec
[math]\displaystyle{ r = 3 }[/math], [math]\displaystyle{ a_{r + 1} = 9 }[/math]
●    [math]\displaystyle{ (9 \mid m) = 1 }[/math] [math]\displaystyle{ 3 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (9 \mid m) = 0 }[/math] [math]\displaystyle{ 3 \mid m }[/math] koniec
●    [math]\displaystyle{ (9 \mid m) \neq - 1 \quad }[/math] - - - - bo [math]\displaystyle{ 9 }[/math] jest liczbą kwadratową


Po wykonaniu trzech prób niezakończonych sukcesem (tzn. wykryciem złożoności [math]\displaystyle{ m }[/math] lub ustaleniem wartości liczb [math]\displaystyle{ D }[/math] i [math]\displaystyle{ Q }[/math]) wiemy, że [math]\displaystyle{ m }[/math] nie jest podzielna przez żadną z liczb pierwszych [math]\displaystyle{ p = 3, 5, 7 }[/math].

[math]\displaystyle{ r }[/math]-ta próba, gdzie [math]\displaystyle{ r \geqslant 4 , \;\; }[/math] wyraz [math]\displaystyle{ a_{r + 1} }[/math]
●    [math]\displaystyle{ (a_{r + 1} \mid m) = 1 }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 1} | = 2 r + 3 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (a_{r + 1} \mid m) = 0 }[/math] A. jeżeli [math]\displaystyle{ m \mid a_{r + 1} }[/math]( * )
B. jeżeli [math]\displaystyle{ m \nmid a_{r + 1} }[/math]
A. przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
B. [math]\displaystyle{ a_{r + 1} \mid m }[/math]( ** ), koniec
●    [math]\displaystyle{ (a_{r + 1} \mid m) = - 1 \quad }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 1} | = 2 r + 3 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     [math]\displaystyle{ D = a_{r + 1} }[/math], [math]\displaystyle{ Q = {\small\frac{1 - a_{r + 1}}{4}} }[/math], koniec

( * ) jest to możliwe tylko dla [math]\displaystyle{ a_{r + 1} = a_{(m - 1) / 2} = m }[/math]

( ** ) zauważmy, że jeżeli [math]\displaystyle{ m \nmid a_{r + 1} }[/math], to [math]\displaystyle{ \gcd (a_{r + 1}, m) = | a_{r + 1} | }[/math], bo gdyby liczba [math]\displaystyle{ | a_{r + 1} | }[/math] była liczbą złożoną, to żaden z jej dzielników pierwszych nie dzieliłby liczby [math]\displaystyle{ m }[/math]


Jeżeli nie została wykryta złożoność liczby [math]\displaystyle{ m }[/math], to żadna z liczb pierwszych [math]\displaystyle{ p \leqslant | a_{r + 1} | = 2 r + 3 }[/math] nie dzieli liczby [math]\displaystyle{ m }[/math]. Zatem [math]\displaystyle{ \gcd (Q, m) \gt 1 }[/math] może być tylko w przypadku, gdy pewna liczba pierwsza [math]\displaystyle{ q \geqslant 2 r + 5 }[/math] będzie wspólnym dzielnikiem liczb [math]\displaystyle{ Q }[/math] i [math]\displaystyle{ m }[/math], ale jest to niemożliwe, bo

[math]\displaystyle{ | Q | = \left| {\small\frac{1 - a_{r + 1}}{4}} \right| \leqslant {\small\frac{| a_{r + 1} | + 1}{4}} = {\small\frac{2 r + 4}{4}} \lt 2 r + 5 \leqslant q }[/math]

Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich [math]\displaystyle{ r }[/math] naturalnych.


Zadanie N31
Zmodyfikujmy metodę Selfridge'a w taki sposób, że będziemy rozpoczynali próby nie od wyrazu [math]\displaystyle{ a_2 = 5 }[/math], ale od wyrazu [math]\displaystyle{ a_3 = - 7 }[/math]. Pokazać, że w przypadku, gdy dla kolejnych liczb [math]\displaystyle{ a_k = (- 1)^k (2 k + 1) }[/math] sprawdzamy, czy konsekwencją [math]\displaystyle{ (a_k \mid m) = 0 }[/math] jest złożoność liczby [math]\displaystyle{ m }[/math], to dla każdej liczby [math]\displaystyle{ Q }[/math] wyznaczonej tak zmodyfikowaną metodą Selfridge'a jest [math]\displaystyle{ \gcd (Q, m) = 1 }[/math].

Rozwiązanie

Poniżej pokażemy, dlaczego musi być [math]\displaystyle{ \gcd (Q, m) = 1 }[/math], gdzie [math]\displaystyle{ Q }[/math] jest liczbą wyznaczoną zmodyfikowaną metodą Selfridge'a (o ile sprawdzana jest złożoność liczby [math]\displaystyle{ m }[/math] przy testowaniu kolejnych liczb [math]\displaystyle{ a_k }[/math]). Pogrubioną czcionką zaznaczone są symbole Jacobiego, które wykryły złożoność liczby [math]\displaystyle{ m }[/math]. Gdyby nie była badana złożoność, to wyliczona zostałaby wartość [math]\displaystyle{ Q }[/math] na podstawie innego wyrazu ciągu [math]\displaystyle{ a_k }[/math] (ten symbol Jacobiego został zapisany zwykłą czcionką).

[math]\displaystyle{ m = 3 , \;\; (- 7 \mid 3) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 5 , \;\; (- 7 \mid 5) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 7 , \;\; (- 7 \mid 7) = 0 , \;\; (- 11 \mid 7) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 }[/math] (zauważmy, że [math]\displaystyle{ (- 7 \mid 7) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 9 , \;\; }[/math] (liczba kwadratowa)
[math]\displaystyle{ m = 11 , \;\; (- 11 \mid 11) = 0 , \;\; (13 \mid 11) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 \;\; }[/math] (zauważmy, że [math]\displaystyle{ (- 11 \mid 11) = 0 }[/math] nie pozwala wnioskować o złożoności)
[math]\displaystyle{ m = 13 , \;\; (- 7 \mid 13) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 15 , \;\; \boldsymbol{(9 \mid 15) = 0} , \;\; (13 \mid 15) = - 1 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)
[math]\displaystyle{ m = 17 , \;\; (- 7 \mid 17) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 19 , \;\; (- 7 \mid 19) = - 1 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 }[/math]
[math]\displaystyle{ m = 21 , \;\; \boldsymbol{(- 7 \mid 21) = 0} , \;\; (- 11 \mid 21) = - 1 , \;\; Q = 3 , \;\; \gcd (m, Q) = 3 \;\; }[/math] (gdyby nie zbadano złożoności)


Niech [math]\displaystyle{ m \geqslant 23 }[/math]. Wiemy, że w ciągu [math]\displaystyle{ ( - 7, 9, \ldots, \pm m, \mp (m + 2), \ldots, - (2 m - 3), 2 m - 1) }[/math] wystąpią liczby [math]\displaystyle{ a_k }[/math] takie, że [math]\displaystyle{ (a_k \mid m) = - 1 }[/math]. Warunek [math]\displaystyle{ (a_k \mid m) = 0 }[/math] oznacza, że [math]\displaystyle{ (2 k + 1 \mid m) = 0 }[/math], bo

[math]\displaystyle{ (a_k \mid m) = ((- 1)^k (2 k + 1) \mid m) = ((- 1)^k \mid m) \cdot (2 k + 1 \mid m) = (- 1 \mid m)^k \cdot (2 k + 1 \mid m) = \pm (2 k + 1 \mid m) }[/math]

Jeżeli będą spełnione warunki [math]\displaystyle{ (a_k \mid m) = 0 }[/math] i [math]\displaystyle{ R_m (a_k) \neq 0 }[/math], to liczba [math]\displaystyle{ m }[/math] będzie liczbą złożoną.

Wypiszmy kolejne próby dla [math]\displaystyle{ m \geqslant 23 }[/math]. Liczba [math]\displaystyle{ r }[/math] jest numerem próby.

[math]\displaystyle{ r = 1 , \;\; a_{r + 2} = - 7 }[/math]
●    [math]\displaystyle{ (- 7 \mid m) = 1 }[/math] [math]\displaystyle{ 7 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 7 \mid m) = 0 }[/math] [math]\displaystyle{ 7 \mid m }[/math] koniec
●    [math]\displaystyle{ (- 7 \mid m) = - 1 \quad }[/math] [math]\displaystyle{ 7 \nmid m }[/math] [math]\displaystyle{ D = - 7 , \;\; Q = 2 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec
[math]\displaystyle{ r = 2 , \;\; a_{r + 2} = 9 }[/math]
●    [math]\displaystyle{ (9 \mid m) = 1 }[/math] [math]\displaystyle{ 3 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (9 \mid m) = 0 }[/math] [math]\displaystyle{ 3 \mid m }[/math] koniec
●    [math]\displaystyle{ (9 \mid m) \neq - 1 \quad }[/math] - - - - bo [math]\displaystyle{ 9 }[/math] jest liczbą kwadratową
[math]\displaystyle{ r = 3 , \;\; a_{r + 2} = - 11 }[/math]
●    [math]\displaystyle{ (- 11 \mid m) = 1 }[/math] [math]\displaystyle{ 11 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 11 \mid m) = 0 }[/math] [math]\displaystyle{ 11 \mid m }[/math] koniec
●    [math]\displaystyle{ (- 11 \mid m) = - 1 \quad }[/math] [math]\displaystyle{ 11 \nmid m }[/math] [math]\displaystyle{ D = - 11 , \;\; Q = 3 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec (bo liczby złożone [math]\displaystyle{ m = 3 k }[/math] zostały usunięte w poprzedniej próbie, [math]\displaystyle{ r = 2 }[/math])
[math]\displaystyle{ r = 4 , \;\; a_{r + 2} = 13 }[/math]
●    [math]\displaystyle{ (13 \mid m) = 1 }[/math] [math]\displaystyle{ 13 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (13 \mid m) = 0 }[/math] [math]\displaystyle{ 13 \mid m }[/math] koniec
●    [math]\displaystyle{ (13 \mid m) = - 1 \quad }[/math] [math]\displaystyle{ 13 \nmid m }[/math] [math]\displaystyle{ D = 13 , \;\; Q = - 3 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec (bo liczby złożone [math]\displaystyle{ m = 3 k }[/math] zostały usunięte w próbie o numerze [math]\displaystyle{ r = 2 }[/math])
[math]\displaystyle{ r = 5 , \;\; a_{r + 2} = - 15 }[/math]
●    [math]\displaystyle{ (- 15 \mid m) = 1 }[/math] [math]\displaystyle{ 5 \nmid m \quad }[/math] przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (- 15 \mid m) = 0 }[/math] [math]\displaystyle{ 5 \mid m }[/math] koniec
●    [math]\displaystyle{ (- 15 \mid m) = - 1 \quad }[/math] [math]\displaystyle{ 5 \nmid m }[/math] [math]\displaystyle{ D = - 15 , \;\; Q = 4 , \;\; \gcd (m, Q) = 1 , \;\; }[/math] koniec


Po wykonaniu pięciu prób niezakończonych sukcesem (tzn. wykryciem złożoności [math]\displaystyle{ m }[/math] lub ustaleniem wartości liczb [math]\displaystyle{ D }[/math] i [math]\displaystyle{ Q }[/math]) wiemy, że [math]\displaystyle{ m }[/math] nie jest podzielna przez żadną z liczb pierwszych [math]\displaystyle{ p = 3, 5, 7, 11, 13 }[/math].

[math]\displaystyle{ r }[/math]-ta próba, gdzie [math]\displaystyle{ r \geqslant 6 , \;\; }[/math] wyraz [math]\displaystyle{ a_{r + 2} }[/math]
●    [math]\displaystyle{ (a_{r + 2} \mid m) = 1 }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 2} | = 2 r + 5 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
●    [math]\displaystyle{ (a_{r + 2} \mid m) = 0 }[/math] A. jeżeli [math]\displaystyle{ m \mid a_{r + 2} }[/math]( * )
B. jeżeli [math]\displaystyle{ m \nmid a_{r + 2} }[/math]
A. przechodzimy do kolejnego wyrazu ciągu [math]\displaystyle{ (a_k) }[/math]
B. [math]\displaystyle{ a_{r + 1} \mid m }[/math]( ** ), koniec
●    [math]\displaystyle{ (a_{r + 2} \mid m) = - 1 \quad }[/math] żadna liczba pierwsza [math]\displaystyle{ p \leqslant | a_{r + 2} | = 2 r + 5 }[/math] nie dzieli liczby [math]\displaystyle{ m \quad }[/math]     [math]\displaystyle{ D = a_{r + 2} }[/math], [math]\displaystyle{ Q = {\small\frac{1 - a_{r + 2}}{4}} }[/math], koniec

( * ) jest to możliwe tylko dla [math]\displaystyle{ a_{r + 2} = a_{(m - 1) / 2} = m }[/math]

( ** ) zauważmy, że jeżeli [math]\displaystyle{ m \nmid a_{r + 2} }[/math], to [math]\displaystyle{ \gcd (a_{r + 2}, m) = | a_{r + 2} | }[/math], bo gdyby liczba [math]\displaystyle{ | a_{r + 2} | }[/math] była liczbą złożoną, to żaden z jej dzielników pierwszych nie dzieliłby liczby [math]\displaystyle{ m }[/math]


Jeżeli nie została wykryta złożoność liczby [math]\displaystyle{ m }[/math], to żadna z liczb pierwszych [math]\displaystyle{ p \leqslant | a_{r + 2} | = 2 r + 5 }[/math] nie dzieli liczby [math]\displaystyle{ m }[/math]. Zatem [math]\displaystyle{ \gcd (Q, m) \gt 1 }[/math] może być tylko w przypadku, gdy pewna liczba pierwsza [math]\displaystyle{ q \geqslant 2 r + 7 }[/math] będzie wspólnym dzielnikiem liczb [math]\displaystyle{ Q }[/math] i [math]\displaystyle{ m }[/math], ale jest to niemożliwe, bo

[math]\displaystyle{ | Q | = \left| {\small\frac{1 - a_{r + 2}}{4}} \right| \leqslant {\small\frac{| a_{r + 2} | + 1}{4}} = {\small\frac{2 r + 6}{4}} \lt 2 r + 7 \leqslant q }[/math]

Przedostatnia (ostra) nierówność jest prawdziwa dla wszystkich [math]\displaystyle{ r }[/math] naturalnych.


Uwaga N32
Przyjmując metodę Selfridge'a wyboru parametrów [math]\displaystyle{ P, Q }[/math] dla testu Lucasa, możemy łatwo napisać odpowiedni program w PARI/GP testujący pierwszość liczb

LucasTest(m) = 
{
local(P, Q, X);
if( m % 2 == 0, return(m == 2) );
if( issquare(m), return(0) ); \\ sprawdzamy, czy m nie jest liczbą kwadratową
X = MethodA(m);
P = X[1];
Q = X[2];
if( P == 0, return(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
if( modLucas(m + 1, P, Q, m)[1] == 0, return(1), return(0) );
}


Uwaga N33
Najmniejsze liczby pseudopierwsze Lucasa, które pojawiają się przy zastosowaniu metody Selfridge'a wyboru parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], to

[math]\displaystyle{ 323, 377, 1159, 1829, 3827, 5459, 5777, 9071, 9179, 10877, 11419, 11663, 13919, 14839, 16109, 16211, 18407, 18971, 19043, 22499, \ldots }[/math]
Pokaż kod
forstep(k=1, 3*10^4, 2, if( LucasTest(k) && !isprime(k), print(k)) )



Tabela przedstawia ilość takich liczb nie większych od [math]\displaystyle{ 10^n }[/math]

Pokaż kod
for(n=3, 9, s=0; forstep(k = 1, 10^n, 2, if( LucasTest(k) && !isprime(k), s++ ) ); print("n= ", n, "   ", s) )




Liczby silnie pseudopierwsze Lucasa

Twierdzenie N34
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą taką, że [math]\displaystyle{ \gcd (p, Q D) = 1 }[/math] oraz [math]\displaystyle{ p - (D \mid p) = 2^r w }[/math], gdzie [math]\displaystyle{ w }[/math] jest liczbą nieparzystą, to spełniony jest dokładnie jeden z warunków

[math]\displaystyle{ U_w \equiv 0 \pmod{p} }[/math]

lub

[math]\displaystyle{ V_{2^k w} \equiv 0 \pmod{p} \qquad }[/math] dla pewnego [math]\displaystyle{ k \in [0, r - 1] }[/math]
Dowód

Wiemy (zobacz N20), że jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą taką, że [math]\displaystyle{ \gcd (p, Q D) = 1 }[/math], to [math]\displaystyle{ p \mid U_{p - (D \mid p)} }[/math]. Z założenia jest [math]\displaystyle{ p - (D \mid p) = 2^r w }[/math], zatem [math]\displaystyle{ p \mid U_{2^r w} }[/math]. Ponieważ założyliśmy, że [math]\displaystyle{ p \nmid Q }[/math] i [math]\displaystyle{ p \nmid D }[/math], to ze wzoru [math]\displaystyle{ V^2_n - D U^2_n = 4 Q^n }[/math] (zobacz N13 p.14) wynika natychmiast, że [math]\displaystyle{ p }[/math] nie może dzielić jednocześnie liczb [math]\displaystyle{ U_n }[/math] i [math]\displaystyle{ V_n }[/math].

Korzystając ze wzoru [math]\displaystyle{ U_{2 n} = U_n V_n }[/math] (zobacz N13 p.11), otrzymujemy

●    [math]\displaystyle{ p \mid U_{2^r w} \;\; \Longleftrightarrow \;\; p \mid U_{2^{r - 1} w} \cdot V_{2^{r - 1} w} \quad }[/math] Jeżeli [math]\displaystyle{ p \mid V_{2^{r - 1} w} }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_{2^{r - 1} w} }[/math], to [math]\displaystyle{ p \mid U_{2^{r - 1} w} }[/math].
●    [math]\displaystyle{ p \mid U_{2^{r - 1} w} \;\; \Longleftrightarrow \;\; p \mid U_{2^{r - 2} w} \cdot V_{2^{r - 2} w} \quad }[/math] Jeżeli [math]\displaystyle{ p \mid V_{2^{r - 2} w} }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_{2^{r - 2} w} }[/math], to [math]\displaystyle{ p \mid U_{2^{r - 2} w} }[/math].
●    [math]\displaystyle{ ................. }[/math]
●    [math]\displaystyle{ p \mid U_{4 w} \;\; \Longleftrightarrow \;\; p \mid U_{2 w} \cdot V_{2 w} }[/math] Jeżeli [math]\displaystyle{ p \mid V_{2 w} }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_{2 w} }[/math], to [math]\displaystyle{ p \mid U_{2 w} }[/math].
●    [math]\displaystyle{ p \mid U_{2 w} \;\; \Longleftrightarrow \;\; p \mid U_w \cdot V_w }[/math] Jeżeli [math]\displaystyle{ p \mid V_w }[/math], to twierdzenie jest dowiedzione. Jeżeli [math]\displaystyle{ p \nmid V_w }[/math], to [math]\displaystyle{ p \mid U_w }[/math].

Z powyższego wynika, że musi być spełniony jeden z wypisanych w twierdzeniu warunków.


Zauważmy teraz, że jeżeli liczba pierwsza [math]\displaystyle{ p }[/math] dzieli [math]\displaystyle{ V_w }[/math], to [math]\displaystyle{ p \nmid U_w }[/math], bo [math]\displaystyle{ p }[/math] nie może jednocześnie być dzielnikiem liczb [math]\displaystyle{ U_w }[/math] i [math]\displaystyle{ V_w }[/math].

Zauważmy też, że jeżeli dla pewnego [math]\displaystyle{ k \in [1, r - 1] }[/math] liczba pierwsza [math]\displaystyle{ p }[/math] dzieli [math]\displaystyle{ V_{2^k w} }[/math], to [math]\displaystyle{ p }[/math] nie dzieli żadnej liczby [math]\displaystyle{ V_{2^j w} }[/math] dla [math]\displaystyle{ j \in [0, k - 1] \;\; \text{i} \;\; p \nmid U_w }[/math]. Istotnie:

●    jeżeli [math]\displaystyle{ p \mid V_{2^k w} }[/math], to [math]\displaystyle{ p \nmid U_{2^k w} \;\; \text{i} \;\; U_{2^k w} = U_{2^{k - 1} w} V_{2^{k - 1} w} }[/math], zatem [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_{2^{k - 1} w} \;\; \text{i} \;\; V_{2^{k - 1} w} }[/math]
●    jeżeli [math]\displaystyle{ p \nmid U_{2^{k - 1} w} \;\; \text{i} \;\; U_{2^{k - 1} w} = U_{2^{k - 2} w} V_{2^{k - 2} w} }[/math], to [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_{2^{k - 2} w} \;\; \text{i} \;\; V_{2^{k - 2} w} }[/math]
●    [math]\displaystyle{ ................. }[/math]
●    jeżeli [math]\displaystyle{ p \nmid U_{4 w} \;\; \text{i} \;\; U_{4 w} = U_{2 w} V_{2 w} }[/math], to [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_{2 w} \;\; \text{i} \;\; V_{2 w} }[/math]
●    jeżeli [math]\displaystyle{ p \nmid U_{2 w} \;\; \text{i} \;\; U_{2 w} = U_w V_w }[/math], to [math]\displaystyle{ p }[/math] nie może być dzielnikiem żadnej z liczb [math]\displaystyle{ U_w \;\; \text{i} \;\; V_w }[/math]


Co dowodzi, że spełniony jest dokładnie jeden z [math]\displaystyle{ r + 1 }[/math] warunków:

[math]\displaystyle{ U_w \equiv 0 \pmod{p} }[/math]
[math]\displaystyle{ V_{2^k w} \equiv 0 \pmod{p} \qquad }[/math] gdzie [math]\displaystyle{ k \in [0, r - 1] }[/math]

Co należało pokazać.


Konsekwentnie definiujemy liczby pseudopierwsze
Definicja N35
Powiemy, że liczba złożona nieparzysta [math]\displaystyle{ m }[/math] jest liczbą silnie pseudopierwszą Lucasa (SLPSP) dla parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], jeżeli [math]\displaystyle{ \gcd (m, Q D) = 1 }[/math] oraz [math]\displaystyle{ m - (D \mid m) = 2^r w }[/math], gdzie [math]\displaystyle{ w }[/math] jest liczbą nieparzystą i spełniony jest jeden z warunków

[math]\displaystyle{ U_w \equiv 0 \pmod{m} }[/math]

lub

[math]\displaystyle{ V_{2^k w} \equiv 0 \pmod{m} \; }[/math] dla pewnego [math]\displaystyle{ k \in [0, r - 1] }[/math]


Uwaga N36
Każda liczba SLPSP([math]\displaystyle{ P, Q }[/math]) jest LPSP([math]\displaystyle{ P, Q }[/math]). Korzystając ze zdefiniowanych wcześniej funkcji: modPower(a, n, m), jacobi(a, n) i modLucas(n, P, Q, m) (zobacz M2, J48, N15), możemy napisać prosty program, który sprawdza, czy liczba [math]\displaystyle{ m }[/math] spełnia jeden z warunków podanych w twierdzeniu N34.

isPrimeOrSLPSP(m, P, Q) = 
{
local(a, b, c, D, js, k, r, w, X);
D = P^2 - 4*Q;
if( gcd(m, 2*Q*D) > 1, return(0) );
js = jacobi(D, m);
r = valuation(m - js, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m - js
w = (m - js) / 2^r;
X =  modLucas(w, P, Q, m);
a = X[1]; \\ U_w(P, Q) % m
b = X[2]; \\ V_w(P, Q) % m
if( a == 0 || b == 0, return(1) ); \\ b == 0 to przypadek k == 0
if( r == 1, return(0) ); \\ nie ma dalszych przypadków
c = modPower(Q, w, m); \\ Q^w % m
k = 0;
\\ sprawdzamy warunek V_(2^k * w) % m = 0; korzystamy ze wzoru V_(2*t) = (V_t)^2 - 2*Q^t
while( k++ < r,
       b = (b^2 - 2*c) % m;
       if( b == 0, return(1) );
       c = c^2 % m;
     );
return(0);
}


Przykład N37
Poniższa tabela zawiera najmniejsze liczby silnie pseudopierwsze Lucasa dla różnych parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math]

Pokaż kod
FirstSLPSP(Stop) = 
\\ najmniejsze SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, 
                  print("Q= ", Q, "   P= ", P, "   ------------------");
                  next();
                );
              m = 3;
              while( m < Stop,
                     if( isPrimeOrSLPSP(m, P, Q)  &&  !isprime(m), 
                         print("Q= ", Q, "   P= ", P, "   m= ", m, "   (D|m)= ", jacobi(D, m));
                         break();
                       );
                     m = m + 2;
                   );
           );
     );
}


Żółtym tłem oznaczyliśmy te najmniejsze liczby pseudopierwsze Lucasa, dla których [math]\displaystyle{ (D \mid m) = - 1 }[/math].


Przykład N38
Ilość liczb SLPSP([math]\displaystyle{ P, Q }[/math]) mniejszych od [math]\displaystyle{ 10^9 }[/math]


Pokaż kod
NumOfSLPSP(Stop) = 
\\ ilość liczb silnie pseudopierwszych Lucasa SLPSP(P,Q) < Stop;  dla 1<=P<=10 i -5<=Q<=5
{
local(D, m, P, Q);
Q = -6;
while( Q++ <= 5,
       if( Q == 0, next() );
       P = 0;
       while( P++ <= 10,
              D = P^2 - 4*Q;
              if( D == 0, print("Q= ", Q, "   P= ", P, "   ------------------"); next() );
              s = 0;
              m = 3;
              while( m < Stop,
                     if( isPrimeOrSLPSP(m, P, Q)  &&  !isprime(m), s++ );
                     m = m + 2;
                   );
              print("Q= ", Q, "   P= ", P, "   s= ", s);
            );
     );
}



Uwaga N39
Można pokazać[2], że dla liczby złożonej nieparzystej [math]\displaystyle{ m \neq 9 }[/math] i ustalonego [math]\displaystyle{ D }[/math] ilość par [math]\displaystyle{ P, Q }[/math] takich, że

  • [math]\displaystyle{ 0 \leqslant P, Q \lt m }[/math]
  • [math]\displaystyle{ \gcd (Q, m) = 1 }[/math]
  • [math]\displaystyle{ P^2 - 4 Q \equiv D \pmod{m} }[/math]
  • [math]\displaystyle{ m }[/math] jest SLPSP([math]\displaystyle{ P, Q }[/math])

nie przekracza [math]\displaystyle{ \tfrac{4}{15} n }[/math].

Nie dotyczy to przypadku, gdy [math]\displaystyle{ m = p (p + 2) }[/math] jest iloczynem liczb pierwszych bliźniaczych takich, że [math]\displaystyle{ (D \mid p) = - (D \mid p + 2) = - 1 }[/math], wtedy mamy słabsze oszacowanie: [math]\displaystyle{ \# (P, Q) \leqslant \tfrac{1}{2} n }[/math]. Zauważmy, że taką sytuację łatwo wykryć, bo w tym przypadku [math]\displaystyle{ m + 1 = (p + 1)^2 }[/math] jest liczbą kwadratową.


Uwaga N40
Podobnie jak w przypadku liczb pseudopierwszych Lucasa LPSP([math]\displaystyle{ P, Q }[/math]) tak i w przypadku liczb silnie pseudopierwszych Lucasa SLPSP([math]\displaystyle{ P, Q }[/math]) możemy testować pierwszość liczby [math]\displaystyle{ m }[/math], wybierając liczby [math]\displaystyle{ P, Q }[/math] losowo lub zastosować wybraną metodę postępowania. Przedstawiony poniżej program, to zmodyfikowany kod z uwagi N36. Teraz parametry [math]\displaystyle{ P, Q }[/math] są wybierane metodą Selfridge'a, a symbol Jacobiego [math]\displaystyle{ (D \mid m) }[/math] jest równy [math]\displaystyle{ - 1 }[/math].

StrongLucasTest(m) =
{
local(a, b, c, k, P, Q, r, w, X);
if( m % 2 == 0, return(m == 2) );
if( issquare(m), return(0) ); \\ sprawdzamy, czy liczba m nie jest kwadratowa
X = MethodA(m);
P = X[1];
Q = X[2];
if( P == 0 || gcd(m, 2*Q) > 1, return(0) ); \\ jeżeli P = 0, to m jest liczbą złożoną
r = valuation(m + 1, 2); \\ znajdujemy wykładnik, z jakim liczba 2 występuje w m + 1
w = (m + 1) / 2^r;
X =  modLucas(w, P, Q, m);
a = X[1]; \\ U_w(P, Q) % m
b = X[2]; \\ V_w(P, Q) % m
if( a == 0 || b == 0, return(1) ); \\ b == 0 to przypadek k == 0
if( r == 1, return(0) ); \\ nie ma dalszych przypadków
c = modPower(Q, w, m); \\ Q^w % m
k = 0;
\\ sprawdzamy warunek V_(2^k * w) %m = 0; korzystamy ze wzoru V_(2*w) = (V_w)^2 - 2*Q^w
while( k++ < r,
       b = (b^2 - 2*c) % m;
       if( b == 0, return(1) );
       c = c^2 % m;
     );
return(0);
}


Uwaga N41
Najmniejsze liczby silnie pseudopierwsze Lucasa, które otrzymujemy po zastosowaniu metody Selfridge'a wyboru parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], to

[math]\displaystyle{ 5459, 5777, 10877, 16109, 18971, 22499, 24569, 25199, 40309, 58519, 75077, 97439, \ldots }[/math]
Pokaż kod
forstep(k=1, 10^5, 2, if( StrongLucasTest(k) && !isprime(k), print(k)) )



Tabela przedstawia ilość takich liczb nie większych od [math]\displaystyle{ 10^n }[/math]

Pokaż kod
for(n=3, 9, s=0; forstep(k = 1, 10^n, 2, if( StrongLucasTest(k) && !isprime(k), s++ ) ); print("n=", n, "   ", s) )




Test BPSW

Uwaga N42
Jest [math]\displaystyle{ 488 }[/math] liczb SPSP([math]\displaystyle{ 2 }[/math]) mniejszych od [math]\displaystyle{ 10^8 }[/math] i są 582 liczby SPSP([math]\displaystyle{ 3 }[/math]) mniejsze od [math]\displaystyle{ 10^8 }[/math] (zobacz M21). Ale jest aż [math]\displaystyle{ 21 }[/math] liczb mniejszych od [math]\displaystyle{ 10^8 }[/math] silnie pseudopierwszych jednocześnie względem podstaw [math]\displaystyle{ 2 }[/math] i [math]\displaystyle{ 3 }[/math]:

[math]\displaystyle{ 1373653, 1530787, 1987021, 2284453, 3116107, 5173601, 6787327, 11541307, 13694761, 15978007, 16070429, }[/math]

[math]\displaystyle{ 16879501, 25326001, 27509653, 27664033, 28527049, 54029741, 61832377, 66096253, 74927161, 80375707 }[/math]

Pokaż kod
forstep(m=3, 10^8, 2, if( isPrimeOrSPSP(m, 2)  &&  isPrimeOrSPSP(m, 3)  &&  !isprime(m), print("m=", m) ) )


Widzimy, że prawdopodobieństwo błędnego rozpoznania pierwszości w przypadku liczb mniejszych od [math]\displaystyle{ 10^8 }[/math] dla podstawy [math]\displaystyle{ 2 }[/math] lub podstawy [math]\displaystyle{ 3 }[/math] jest rzędu kilku milionowych. Gdyby prawdopodobieństwa błędnego rozpoznania pierwszości w przypadku podstawy [math]\displaystyle{ 2 }[/math] lub podstawy [math]\displaystyle{ 3 }[/math] były niezależne, to spodziewalibyśmy się, że nie będzie wcale liczb mniejszych od [math]\displaystyle{ 10^8 }[/math] silnie pseudopierwszych jednocześnie względem podstaw [math]\displaystyle{ 2 }[/math] i [math]\displaystyle{ 3 }[/math], bo prawdopodobieństwo takiego zdarzenia byłoby równe kilkudziesięciu bilonowym. Ale tak nie jest.

Jest to mocny argument za tym, że zastosowanie różnych (niezależnych) testów może być znacznie silniejszym narzędziem do testowania pierwszości liczb, niż wielokrotne stosowanie tego samego testu, gdzie poszczególne próby są tylko pozornie niezależne.

Połączenie znanych nam już testów prowadzi do prostego programu

BPSWtest(m) =
{
forprime(p = 2, 1000, if( m % p > 0, next() ); if( m == p, return(1), return(0) ));
if( !isPrimeOrSPSP(m, 2), return(0) );
if( !StrongLucasTest(m), return(0), return(1) );
}


Funkcja BPSWtest(m) kolejno sprawdza:

  • czy liczba [math]\displaystyle{ m }[/math] jest podzielna przez niewielkie liczby pierwsze (w naszym przypadku mniejsze od [math]\displaystyle{ 1000 }[/math]); jeśli tak, to sprawdza, czy [math]\displaystyle{ m }[/math] jest liczbą pierwszą, czy złożoną i zwraca odpowiednio [math]\displaystyle{ 1 }[/math] lub [math]\displaystyle{ 0 }[/math]
  • czy liczba [math]\displaystyle{ m }[/math] przechodzi test Millera-Rabina dla podstawy [math]\displaystyle{ 2 }[/math]; jeśli nie, to zwraca [math]\displaystyle{ 0 }[/math]
  • czy liczba [math]\displaystyle{ m }[/math] przechodzi silny test Lucasa dla parametrów [math]\displaystyle{ P }[/math] i [math]\displaystyle{ Q }[/math], które wybieramy metodą Selfridge'a; jeśli nie, to zwraca [math]\displaystyle{ 0 }[/math], w przeciwnym wypadku zwraca [math]\displaystyle{ 1 }[/math]


Test w dokładnie takiej postaci zaproponowali Robert Baillie i Samuel Wagstaff[1]. Nazwa testu to akronim, utworzony od pierwszych liter nazwisk Roberta Bailliego, Carla Pomerance'a, Johna Selfridge'a i Samuela Wagstaffa.

Nie jest znany żaden przykład liczby złożonej [math]\displaystyle{ m }[/math], którą test BPSW[3][4] identyfikowałby jako pierwszą i z pewnością nie ma takich liczb dla [math]\displaystyle{ m \lt 2^{64} \approx 1.844 \cdot 10^{19} }[/math]. Warto przypomnieć: potrzebowaliśmy siedmiu testów Millera-Rabina (dla podstaw [math]\displaystyle{ 2, 3, 5, 7, 11, 13, 17 }[/math]), aby mieć pewność, że dowolna liczba [math]\displaystyle{ m \lt 3.41 \cdot 10^{14} }[/math] jest pierwsza (zobacz M22).



Uzupełnienia

 

Pewne własności współczynników dwumianowych

 

Twierdzenie N43
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą, to

[math]\displaystyle{ \binom{p}{k} \equiv 0 \pmod{p} }[/math]

dla każdego [math]\displaystyle{ k \in [1, p - 1] }[/math].

Dowód

Łatwo zauważamy, że dla [math]\displaystyle{ k \in [1, p - 1] }[/math] liczba pierwsza [math]\displaystyle{ p }[/math] dzieli licznik, ale nie dzieli mianownika współczynnika dwumianowego

[math]\displaystyle{ \binom{p}{k} = {\small\frac{p!}{k! \cdot (p - k)!}} }[/math]

zatem [math]\displaystyle{ p \biggr\rvert \binom{p}{k} }[/math]. Co należało pokazać.


Twierdzenie N44
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą, to

[math]\displaystyle{ \binom{p + 1}{k} \equiv 0 \pmod{p} }[/math]

dla każdego [math]\displaystyle{ k \in [2, p - 1] }[/math].

Dowód

Jeżeli [math]\displaystyle{ k \in [2, p - 1] }[/math], to modulo [math]\displaystyle{ p }[/math] dostajemy

[math]\displaystyle{ \binom{p + 1}{k} = \binom{p}{k} + \binom{p}{k - 1} \equiv 0 \pmod{p} }[/math]

Bo liczba pierwsza [math]\displaystyle{ p }[/math] dzieli licznik, ale nie dzieli mianownika współczynników dwumianowych po prawej stronie. Co należało pokazać.


Twierdzenie N45
Jeżeli [math]\displaystyle{ p }[/math] jest liczbą pierwszą, to

[math]\displaystyle{ \binom{p - 1}{k} \equiv (- 1)^k \pmod{p} }[/math]

dla każdego [math]\displaystyle{ k \in [0, p - 1] }[/math].

Dowód

Łatwo sprawdzamy, że twierdzenie jest prawdziwe dla liczby pierwszej parzystej [math]\displaystyle{ p = 2 }[/math]. Załóżmy, że [math]\displaystyle{ p }[/math] jest liczbą pierwszą nieparzystą. Równie łatwo sprawdzamy, że twierdzenie jest prawdziwe dla [math]\displaystyle{ k = 0 }[/math] i [math]\displaystyle{ k = 1 }[/math]. Zauważmy, że dla [math]\displaystyle{ k \in [1, p - 1] }[/math] jest

[math]\displaystyle{ \binom{p - 1}{k} = {\small\frac{(p - 1) !}{k! (p - 1 - k) !}} = {\small\frac{p - k}{k}} \cdot {\small\frac{(p - 1) !}{(k - 1) ! (p - k) !}} = {\small\frac{p - k}{k}} \cdot \binom{p - 1}{k - 1} = {\small\frac{p}{k}} \cdot \binom{p - 1}{k - 1} - \binom{p - 1}{k - 1} }[/math]

Ponieważ współczynniki dwumianowe są liczbami całkowitymi, a liczba [math]\displaystyle{ k \in [2, p - 1] }[/math] nie dzieli liczby pierwszej nieparzystej [math]\displaystyle{ p }[/math], to [math]\displaystyle{ k }[/math] musi dzielić liczbę [math]\displaystyle{ \binom{p - 1}{k - 1} }[/math]. Zatem dla [math]\displaystyle{ k \in [2, p - 1] }[/math] modulo [math]\displaystyle{ p }[/math] mamy

[math]\displaystyle{ \binom{p - 1}{k} \equiv - \binom{p - 1}{k - 1}\pmod{p} }[/math]

Skąd otrzymujemy

[math]\displaystyle{ \binom{p - 1}{k} \equiv (- 1)^1 \binom{p - 1}{k - 1} \equiv (- 1)^2 \binom{p - 1}{k - 2} \equiv \ldots \equiv (- 1)^{k - 2} \binom{p - 1}{2} \equiv (- 1)^{k - 1} \binom{p - 1}{1} \equiv (- 1)^k \pmod{p} }[/math]

Co należało pokazać. Zobacz też zadanie H22.


Twierdzenie N46
Dla współczynników dwumianowych prawdziwe są następujące wzory

[math]\displaystyle{ \underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1} }[/math]
[math]\displaystyle{ \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1} }[/math]
Dowód

Ze wzoru dwumianowego

[math]\displaystyle{ (a + b)^n = \sum_{k = 0}^{n} \binom{n}{k} a^{n - k} b^k }[/math]

z łatwością otrzymujemy

[math]\displaystyle{ (1 + 1)^n = \sum_{k = 0}^{n} \binom{n}{k} = 2^n }[/math]
[math]\displaystyle{ (1 - 1)^n = \sum_{k = 0}^{n} (- 1)^k \binom{n}{k} = 0 }[/math]

Obliczając sumę i różnicę powyższych wzorów mamy

[math]\displaystyle{ \sum_{k = 0}^{n} \binom{n}{k} (1 + (- 1)^k) = 2 \underset{k \; \text{parzyste}}{\sum^n_{k = 0}} \binom{n}{k} = 2^n }[/math]
[math]\displaystyle{ \sum_{k = 0}^{n} \binom{n}{k} (1 - (- 1)^k) = 2 \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^n }[/math]

Skąd natychmiast wynika

[math]\displaystyle{ \underset{k \; \text{parzyste}}{\sum_{k = 0}^{n}} \binom{n}{k} = 2^{n - 1} }[/math]
[math]\displaystyle{ \underset{k \; \text{nieparzyste}}{\sum_{k = 1}^{n}} \binom{n}{k} = 2^{n - 1} }[/math]

Co należało pokazać.



Funkcje digits(m, b) oraz issquare(m)

 

Uwaga N47
W funkcji modLucas() wykorzystaliśmy zaimplementowaną w PARI/GP funkcję

digits(m, b) – zwraca wektor cyfr liczby [math]\displaystyle{ | m | }[/math] w systemie liczbowym o podstawie [math]\displaystyle{ b }[/math]

W naszym przypadku potrzebowaliśmy uzyskać wektor cyfr liczby [math]\displaystyle{ m }[/math] w układzie dwójkowym, czyli funkcję digits(m, 2) . Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Zauważmy, że do zapisania liczby [math]\displaystyle{ m \geqslant 1 }[/math] potrzebujemy [math]\displaystyle{ \log_2 m + 1 }[/math] cyfr. Zastępując funkcję [math]\displaystyle{ \log_2 m }[/math] funkcją [math]\displaystyle{ \left \lfloor \tfrac{\log m}{\log 2} \right \rfloor }[/math] musimy liczyć się z możliwym błędem zaokrąglenia – dlatego w programie deklarujemy wektor V o długości floor( log(m)/log(2) ) + 2. Zwracany wektor W ma już prawidłową długość.

Dec2Bin(m) = 
\\ zwraca wektor cyfr liczby m w układzie dwójkowym
{
local(i, k, V, W);
if( m == 0, return([0]) );
V = vector( floor( log(m)/log(2) ) + 2 ); \\ potrzeba floor( log(m)/log(2) ) + 1, ale błąd zaokrąglenia może zepsuć wynik
k = 0;
while( m > 0,
       V[k++] = m % 2;
       m = floor(m / 2);
     );
W = vector(k);
for(i = 1, k, W[i] = V[k + 1 - i]);
return(W);
}


Uwaga N48
W funkcjach LucasTest() i StrongLucasTest() wykorzystaliśmy zaimplementowaną w PARI/GP funkcję

issquare(m) – sprawdza, czy liczba [math]\displaystyle{ m }[/math] jest liczbą kwadratową

Wprowadzenie tej funkcji pozwoliło zwiększyć czytelność kodu, ale bez trudu możemy ją sami napisać. Potrzebna nam będzie funkcja, która znajduje całość z pierwiastka z liczby [math]\displaystyle{ m }[/math], czyli [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor }[/math]. Wykorzystamy tutaj ciąg

[math]\displaystyle{ a_{k + 1} = \begin{cases} \qquad \;\; 1 & \text{gdy } k = 0 \\ \tfrac{1}{2} \left( a_k + \tfrac{x}{a_k} \right) & \text{gdy } k \gt 0 \\ \end{cases} }[/math]

którego granicą jest [math]\displaystyle{ \sqrt{x} }[/math] [5].

Modyfikując powyższą definicję tak, aby operacje były zawsze wykonywane na liczbach całkowitych[6]

[math]\displaystyle{ a_{k + 1} = \begin{cases} \qquad \quad \; 1 & \text{gdy } k = 0 \\ \left\lfloor \tfrac{1}{2} \left( a_k + \left\lfloor \tfrac{m}{a_k} \right\rfloor \right) \right\rfloor & \text{gdy } k \gt 0 \\ \end{cases} }[/math]

otrzymujemy ciąg, którego wszystkie wyrazy, począwszy od pewnego skończonego [math]\displaystyle{ n_0 }[/math], są równe [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor }[/math]. Nie dotyczy to przypadku, gdy [math]\displaystyle{ m + 1 }[/math] jest liczbą kwadratową, wtedy, począwszy od pewnego skończonego [math]\displaystyle{ n_0 }[/math], wyrazy ciągu przyjmują na zmianę wartości [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor }[/math] oraz [math]\displaystyle{ \left\lfloor \sqrt{m} \right\rfloor + 1 }[/math].

Na tej podstawie możemy w PARI/GP napisać funkcję

intSqrt(m) = 
{
local(a, b);
if( m == 0, return(0) );
a = 2^( floor( log(m)/log(2)/2 ) + 2 ); \\ musi być a > sqrt(m)
b = floor(( a + floor( m/a ) )/2);
while( b < a,
       a = b;
       b = floor( ( a + floor(m/a) )/2 );
     );
return(a);
}

Oczywiście liczba [math]\displaystyle{ m }[/math] jest liczbą kwadratową, wtedy i tylko wtedy, gdy [math]\displaystyle{ m = \left\lfloor \sqrt{m} \right\rfloor^2 }[/math], zatem wystarczy sprawdzić, czy m == intSqrt(m)^2.








Przypisy

  1. 1,0 1,1 Robert Baillie and Samuel S. Wagstaff Jr., Lucas Pseudoprimes, Mathematics of Computation Vol. 35, No. 152 (1980), (LINK)
  2. François Arnault, The Rabin-Monier Theorem for Lucas Pseudoprimes, Mathematics of Computation Vol. 66, No. 218 (1997)
  3. Wikipedia, Baillie–PSW primality test, (Wiki-en)
  4. MathWorld, Baillie-PSW Primality Test, (LINK)
  5. Wikipedia, Pierwiastek kwadratowy, (Wiki-pl), (Wiki-en)
  6. Wikipedia, Integer square root, (Wiki-en)