-
Notifications
You must be signed in to change notification settings - Fork 0
/
$620 generation.sf
72 lines (52 loc) · 1.45 KB
/
$620 generation.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/ruby
# Author: Daniel "Trizen" Șuteu
# Date: 21 September 2018
# https://github.com/trizen
# A new algorithm for generating Fibonacci pseudoprimes.
# See also:
# https://oeis.org/A081264 -- Odd Fibonacci pseudoprimes.
# https://oeis.org/A212424 -- Frobenius pseudoprimes with respect to Fibonacci polynomial x^2 - x - 1.
func fibonacci_pseudoprimes(limit) {
var table = Hash()
File("b018188.txt").open_r.each {|line|
var p = (line.nums[1] || next)
for d in (p - p.legendre(5) -> divisors) {
if (fibmod(d, p) == 0) {
table{d} := [] << p
}
}
}
for p in (primes(1_000_000)) {
for d in (p - p.legendre(5) -> divisors) {
if (fibmod(d, p) == 0) {
table{d} := [] << p
}
}
}
gather {
table.each_v { |a|
a.uniq!
var L = a.len
L > 1 || next
for k in (2..L) {
a.subsets(k, {|*t|
take(t.prod)
})
}
}
}.uniq
}
func is_fibonacci_pseudoprime(n) {
fibmod(n - n.legendre(5), n) == 0
}
var pseudoprimes = fibonacci_pseudoprimes(10000)
pseudoprimes.each {|n|
say "Testing: #{n}"
assert(is_fibonacci_pseudoprime(n))
if (n.legendre(5) == -1) {
if (powmod(2, n-1, n) == 1) {
die "Found a special pseudoprime: #{n}"
}
}
}
#say pseudoprimes.sort