Quellcode durchsuchen

Fix "first D" to deal with "0"s; compare values with sieve, hund_div

First D algorithm stuff from
<http://dx.doi.org/10.1090/S0025-5718-1980-0583518-6> - if the Jacobi
(D/n) is 0, D is a factor of n.
Petra Lamborn vor 5 Jahren
Ursprung
Commit
a16ee6a8bd
1 geänderte Dateien mit 15 neuen und 18 gelöschten Zeilen
  1. 15
    18
      lucas.py

+ 15
- 18
lucas.py Datei anzeigen

2
 from math import sqrt, gcd, floor, log
2
 from math import sqrt, gcd, floor, log
3
 from time import process_time
3
 from time import process_time
4
 from psimp import trd, hund_div
4
 from psimp import trd, hund_div
5
+from sieve import sieve
5
 
6
 
6
 def isqrt(n):
7
 def isqrt(n):
7
     """ Find the integer square root of n via newton's method, code via
8
     """ Find the integer square root of n via newton's method, code via
92
     # square
93
     # square
93
     haschecked = False
94
     haschecked = False
94
     for D in Dsequence():
95
     for D in Dsequence():
95
-        if Jacobi(D, n) == -1:
96
+        Jv = Jacobi(D, n)
97
+        # What we're looking for
98
+        if Jv == -1:
96
             return D
99
             return D
97
-        # This is supposed to be faster
98
-        if D > 30 and not haschecked:
100
+        # Have found a factor
101
+        if Jv == 0 and abs(D) != n:
102
+            return 0
103
+        # Check for square at 13
104
+        if D > 10 and not haschecked:
99
             if hasIntSQRT(n):
105
             if hasIntSQRT(n):
100
                 return 0
106
                 return 0
101
     # Shouldn't fire
107
     # Shouldn't fire
234
 
240
 
235
 
241
 
236
 
242
 
237
-#print(StrongLucasPrime(7))
238
-
239
-np = 0
240
-
241
-for i in range(10000):
243
+mp = 400000
244
+ap = sieve(mp)
245
+for i in range(mp):
246
+    iip = i in ap
242
     lp = StrongLucasPrime(i)
247
     lp = StrongLucasPrime(i)
243
-    if lp:
244
-        np = np + 1
245
-        print("{}:\t{};\t{}".format(i, lp, np))
246
-
247
-print(np)
248
-
249
-print(StrongLucasPrime(5459))
250
-print(hund_div(5459))
251
-print(StrongLucasPrime(5777))
252
-print(hund_div(5777))
248
+    if iip != lp:
249
+        print(iip, lp, i, hund_div(i), sep='\t')
253
 
250
 
254
 
251