-
Notifications
You must be signed in to change notification settings - Fork 0
/
twin_lucas.pl
executable file
·53 lines (38 loc) · 2.36 KB
/
twin_lucas.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
#!/usr/bin/perl
# Bruckman-Lucas pseudoprimes that differ by 2.
# Known pairs:
# 192900153617 192900153619
# 7177905237579946589743592924684177 7177905237579946589743592924684179
# More pairs are given by A006276:
# https://oeis.org/A006276 -- Pierce expansion of (3 - sqrt(5))/2.
use 5.036;
use Math::GMPz;
use ntheory qw(:all);
use Math::Prime::Util::GMP qw();
my %seen;
sub is_Bruckman_Lucas_pseudoprimes ($n) {
Math::Prime::Util::GMP::lucasvmod(1, -1, $n, $n) eq '1';
}
while (<>) {
next if /^\h*#/;
/\S/ or next;
my $n = (split(' ', $_))[-1];
$n || next;
is_Bruckman_Lucas_pseudoprimes($n) || next;
if ($n > ((~0) >> 1)) {
$n = Math::GMPz->new("$n");
}
if (is_Bruckman_Lucas_pseudoprimes($n + 2) and !is_prime($n + 2)) {
say $n if !$seen{$n}++;
}
if (is_Bruckman_Lucas_pseudoprimes($n - 2) and !is_prime($n - 2)) {
say($n - 2) if !$seen{$n - 2}++;
}
}
__END__
# Numbers m such that m and m+2 are both Bruckman-Lucas pseudoprimes:
192900153617
7177905237579946589743592924684177
369822356418414944143680173221426891716916679027557977938929258031490127514207143830378340325399155217
50580076803975783038761530275339781402780628412919460817762444970127859280289423467192498630726832587273673620561747116076218453123123476455610413145534405143460447615343102837820328461895208940047190971018488274781762771163341157885243609978772022860552828530787331582441862268883997606792363679489554577
129401244584115823457377310152181072363956665035872446687197587393372147287961770341150276934449397643592142802199212639530080733367166416029142717533852720789231538228249083916592747481373832694393756926881653776577424060473762470923318112106903004332582900460566875938094888348490013909014372654876198344503724093237423583896811734669533812915111708748005513783919346646224493127515481411462324325059144522169494592233804177810495635776810930410242403311369537188737672651245313611338665495902390188460668184925736209002007237423824649570055468620772628962489387319146364387577384848820214438745332604412076368794620359287550638998728011148445540739637499801840460307764325017245909203774749783023079075063385947030758039424517240026262355923639367740212945687772907989398541547834769186653408613628953771289583885160187356017630978085095076884587210795750860336248006275956635048842991434958253478744390544044817