|
@@ -162,34 +162,32 @@ def LucasFast(k, p, q, n):
|
162
|
162
|
tp = tp // 2
|
163
|
163
|
return(uc, vc)
|
164
|
164
|
|
165
|
|
-
|
166
|
|
-for i in range(1, 20, 2):
|
167
|
|
- if hasIntSQRT(i):
|
168
|
|
- continue
|
169
|
|
- d = FirstD(i)
|
|
165
|
+def LucasPrime(n):
|
|
166
|
+ """Lucas probable prime test
|
|
167
|
+ (note: not the "strong" test.)
|
|
168
|
+ """
|
|
169
|
+ if n < 2:
|
|
170
|
+ return False
|
|
171
|
+ if n == 2:
|
|
172
|
+ return True
|
|
173
|
+ if n % 2 == 0:
|
|
174
|
+ return False
|
|
175
|
+ d = FirstD(n)
|
|
176
|
+ if d == 0:
|
|
177
|
+ return False
|
170
|
178
|
q = (1 - d) // 4
|
171
|
|
- fu, fv = LucasFast(i + 1, 1, q, i)
|
172
|
|
- su, sv = Lucas(i + 1, 1, q)
|
173
|
|
- su = su % i
|
174
|
|
- sv = sv % i
|
175
|
|
- if (fu != su) or (fv != sv):
|
176
|
|
- print("{}: {}, {}; {} {}".format(i, fu, fv, su, sv))
|
177
|
|
-print("Done!")
|
178
|
|
-
|
179
|
|
-i = 19999999999999999999999999999999999999999999999999999999999
|
180
|
|
-t1 = process_time()
|
181
|
|
-hasIntSQRT(i)
|
182
|
|
-te = process_time() - t1
|
183
|
|
-print(te)
|
184
|
|
-t1 = process_time()
|
185
|
|
-d = FirstD(i)
|
186
|
|
-te = process_time() - t1
|
187
|
|
-print(te)
|
188
|
|
-q = (1 - d) // 4
|
189
|
|
-t1 = process_time()
|
190
|
|
-LucasFast(i + 1, 1, q, i)
|
191
|
|
-te = process_time() - t1
|
192
|
|
-print(te)
|
193
|
|
-t1 = process_time()
|
|
179
|
+ lnum = LucasFast(n + 1, 1, q, n)
|
|
180
|
+ return lnum[0] == 0
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+np = 0
|
|
184
|
+
|
|
185
|
+for i in range(1000):
|
|
186
|
+ lp = LucasPrime(i)
|
|
187
|
+ if lp:
|
|
188
|
+ np = np + 1
|
|
189
|
+ print("{}:\t{}".format(i, lp))
|
|
190
|
+
|
|
191
|
+print(np)
|
194
|
192
|
|
195
|
193
|
|