-
Notifications
You must be signed in to change notification settings - Fork 0
/
carmichael_euler_phi.pl
56 lines (38 loc) · 1.01 KB
/
carmichael_euler_phi.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
#!/usr/bin/perl
use 5.014;
use strict;
use warnings;
use Math::GMPz;
use Math::Prime::Util::GMP qw(totient is_carmichael);
use experimental qw(signatures);
sub big_euler_phi ($n) {
if (length("$n") > 50) {
say "Big input: ", length($n), " digits";
my $res = eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 30;
chomp(my $test = `$^X -MMath::Prime::Util::GMP=totient -E 'say totient("$n")'`);
alarm 0;
return Math::GMPz->new($test);
};
return $res if defined($res);
return undef;
}
say "Small input: $n";
Math::GMPz->new(totient($n));
}
my %seen;
while (<>) {
/\S/ || next;
# /Fermat/ or next;
if (/: (\d+)$/) {
next if $seen{$1}++;
my $n = Math::GMPz->new($1);
is_carmichael($n) || next;
my $phi = big_euler_phi($n) // next;
say "phi($n) = $phi";
if (($n-1)% $phi == 0) {
die "Found counter-example: $n";
}
}
}