-
Notifications
You must be signed in to change notification settings - Fork 0
/
carmichael_generate.pl
executable file
·62 lines (47 loc) · 1.37 KB
/
carmichael_generate.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
#!/usr/bin/perl
# Generate Carmichael numbers.
use 5.020;
use warnings;
use experimental qw(signatures);
use Math::AnyNum qw(prod);
use ntheory qw(:all);
use List::Util qw(uniq);
use Math::Prime::Util::GMP qw(is_pseudoprime vecprod is_carmichael);
sub fermat_pseudoprimes ($limit) {
my %common_divisors;
warn "Sieving...\n";
forprimes {
my $p = $_;
my $z1 = znorder(2, $p);
my $z2 = ($p == 3) ? (3-1) : znorder(3, $p);
my $z3 = ($p == 5) ? (5-1) : znorder(5, $p);
my $z4 = ($p == 7) ? (7-1) : znorder(7, $p);
foreach my $d (divisors($p - 1)) {
if (
gcd($d, $z1) == $z1
#and gcd($d, $z2) == $z2
#and gcd($d, $z3) == $z3
and gcd($d, $z4) == $z4
) {
foreach my $k (1..50) {
push @{$common_divisors{$d*$k}}, $p;
}
}
}
} 3, $limit;
warn "Combinations...\n";
foreach my $arr (values %common_divisors) {
@$arr = uniq(@$arr);
my $l = $#{$arr} + 1;
foreach my $k (3 .. $l) {
forcomb {
my $n = vecprod(@{$arr}[@_]);
if ($n > ~0 and is_carmichael($n)) {
warn "$n\n";
say $n;
}
} $l, $k;
}
}
}
fermat_pseudoprimes(1e5);