-
Notifications
You must be signed in to change notification settings - Fork 0
/
carmichael_n-2_and_n+2_are_prime.pl
executable file
·130 lines (117 loc) · 2.47 KB
/
carmichael_n-2_and_n+2_are_prime.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl
# Carmichael numbers n such that n-2 and n+2 are both primes.
# https://oeis.org/A287591
# Observation:
# n must be divisible by 3, otherwise either n-2 or n+2 is a multiple of 3.
use 5.020;
use strict;
use warnings;
use experimental qw(signatures);
use Math::GMPz;
use Math::Prime::Util::GMP qw(subint addint is_carmichael is_prime modint);
my %seen;
my @nums;
while (<>) {
next if /^\h*#/;
/\S/ or next;
my $n = (split(' ', $_))[-1];
$n || next;
if (modint($n, 3) == 0 and is_prime(subint($n, 2)) and is_prime(addint($n, 2)) and is_carmichael($n)) {
push @nums, $n;
}
}
@nums = sort { $a <=> $b } @nums;
foreach my $n (@nums) {
if ($n > ~0) {
say $n;
}
}
__END__
656601
25536531021
8829751133841
60561233400921
79934093254401
352609909731201
598438077923841
976515437206401
2122162714918401
2789066007968241
3767175573114801
7881891474971361
10740122274670881
11512252145095521
16924806963384321
23399228613313281
35151891169379601
37714616944835601
55450863728624001
57870787858499001
89283676825965441
143061782005382241
171577107519356001
176946672962737569
209606994019068801
223437642562870401
382921793061167361
512885133394634001
524960299326108801
574688716797530721
584047819872236721
627126355430628801
785648445938610801
798174191224351761
818512506266362881
981400306837714401
1107574117930742001
1127448525937353621
1133677361332947201
1146571771624716081
1152431453119654401
1344418370696745345
1519293267472386561
2148420217028004921
2151281833968350721
2219654785766232081
2990125943388676401
3002696344225978401
4491083051676478401
4687106597772216801
5074682476684376721
5124378229051676001
5573559600718487841
5993089007757031041
6019222085781142785
6070622657341282041
6404240106849264681
6820040235625712481
6919232969930803761
6997908515945547201
7184549603549545041
7691501233385409441
7847051237982413601
8890523804962042881
8960867461386317121
9012735525714746001
9349309466067771201
9869213653669845201
9911251496686398321
10015999303573000401
10220044365330320361
10265120470687780545
11383971442428041601
11768616425247584001
12145779532635989241
14159356777813741521
15675663568597450881
16109304624347792001
16577856335614038081
# Extra terms:
454609621733915782401
482242506590172692001
192189648528301092372705
37814155353461793596561601
343281297784639620588304305
120460105372321524476849927361
2839125759995828031418180270035201
5305277875219513142363733158395966192315520354250843835568159698877116665179985