-
Notifications
You must be signed in to change notification settings - Fork 0
/
carmichael_of_order_2_cached.pl
executable file
·64 lines (47 loc) · 1.56 KB
/
carmichael_of_order_2_cached.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
#!/usr/bin/perl
# Carmichael numbers of order 2.
# https://oeis.org/A175531
# Known terms:
# 443372888629441, 39671149333495681, 842526563598720001, 2380296518909971201, 3188618003602886401
# See also:
# https://listserv.nodak.edu/cgi-bin/wa.exe?A2=NMBRTHRY;1d24d4ee.1006
# Interesting Carmichael number, which is also a Chebyshev pseudoprime:
# 122762671289519184001
# New term:
# 713211736645623197793013755552001
use 5.036;
use Storable;
use Math::GMPz;
use ntheory qw(:all);
use Math::Prime::Util::GMP;
my $storable_file = "cache/factors-carmichael.storable";
my $table = retrieve($storable_file);
sub is_chebyshev_pseudoprime ($n) {
foreach (1 .. 20) {
my $p = int(rand(1e6)) + 5;
my $v = ($n > ~0) ? Math::Prime::Util::GMP::lucasvmod($p, 1, $n, $n) : lucasvmod($p, 1, $n, $n);
$v eq $p or return 0;
}
return 1;
}
my $n = Math::GMPz::Rmpz_init();
my $p = Math::GMPz::Rmpz_init();
my $one = Math::GMPz::Rmpz_init_set_ui(1);
while (my ($key, $value) = each %$table) {
Math::GMPz::Rmpz_set_str($n, $key, 10);
#is_chebyshev_pseudoprime($n) || next;
if (
vecall {
Math::GMPz::Rmpz_set_str($p, $_, 10);
Math::GMPz::Rmpz_mul($p, $p, $p);
Math::GMPz::Rmpz_sub_ui($p, $p, 1);
Math::GMPz::Rmpz_congruent_p($n, $one, $p);
}
split(' ', $value)
) {
say $n;
}
}
__END__
713211736645623197793013755552001
5289317030813845025030136441759313676350437291809581944424604404172556336793009975663443300209602618534779461700271078886792582401