-
Notifications
You must be signed in to change notification settings - Fork 0
/
nine_nine_nine_pseudoprimes.pl
executable file
·80 lines (63 loc) · 2.05 KB
/
nine_nine_nine_pseudoprimes.pl
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
73
74
75
76
77
78
79
80
#!/usr/bin/perl
# Find new Fibonacci / Lucas pseudoprimes, by appending a run of 9's at the end of other pseudoprimes.
# Curious example:
# 430479503 # is a Fibonacci/Lucas pseudoprime
# 43047950399 # is a Fibonacci/Lucas pseudoprime
# 4304795039999 # is a Pell pseudoprime
# Also:
# 430479503 = 20747 * 20749
# 43047950399 = 207479 * 207481
# 4304795039999 = 2074799 * 2074801
use 5.020;
use strict;
use warnings;
use experimental qw(signatures);
use Math::GMPz;
use Math::Prime::Util::GMP qw(is_prob_prime is_pseudoprime is_lucas_pseudoprime is_extra_strong_lucas_pseudoprime is_almost_extra_strong_lucas_pseudoprime);
sub is_fibonacci_pseudoprime ($n) {
Math::Prime::Util::GMP::lucasumod(1, -1, Math::Prime::Util::GMP::subint($n, kronecker($n, 5)), $n) eq '0';
}
sub is_lucas_carmichael ($n) {
my $t = Math::GMPz->new($n) + 1;
vecall { $t % ($_ + 1) == 0 } factor($n);
}
while (<>) {
next if /^\h*#/;
/\S/ or next;
my $n = (split(' ', $_))[-1];
#next if ($n <= 6479);
#next if ($n > ((~0)>>1));
#<<<
#~ while (substr($n, -1) eq '9') {
#~ chop $n;
#~ $n eq '' and last;
#~ (substr($n, -1) & 1) || last;
#~ is_prob_prime($n) && next;
#~ if (is_lucas_pseudoprime($n)) {
#~ say $n;
#~ }
#~ elsif (is_fibonacci_pseudoprime($n)) {
#~ say $n;
#~ }
#~ }
#>>>
next if length($n) > 100;
is_pseudoprime($n, 2) && next;
if ( is_lucas_pseudoprime($n)
or is_extra_strong_lucas_pseudoprime($n)
or is_almost_extra_strong_lucas_pseudoprime($n)) {
#if (1) {
foreach my $k (1 .. 9) {
my $t = $n . ('9' x $k);
is_prob_prime($t) && next;
if ( is_lucas_pseudoprime($t)
or is_extra_strong_lucas_pseudoprime($t)
or is_almost_extra_strong_lucas_pseudoprime($t)) {
say $t;
}
#elsif (is_fibonacci_pseudoprime($t)) {
# say $t;
#}
}
}
}