-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlehmer_totient_conjecture_cached.pl
executable file
·55 lines (38 loc) · 1.22 KB
/
lehmer_totient_conjecture_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
#!/usr/bin/perl
# https://oeis.org/A306828
# https://en.wikipedia.org/wiki/Lehmer%27s_totient_problem
use 5.020;
use strict;
use warnings;
use experimental qw(signatures);
use Storable;
use Math::GMPz;
use ntheory qw(:all);
use Math::Prime::Util::GMP;
use experimental qw(signatures);
my $carmichael_file = "cache/factors-carmichael.storable";
my $carmichael = retrieve($carmichael_file);
sub odd_part ($n) {
$n >> valuation($n, 2);
}
sub my_euler_phi ($factors) { # assumes n is squarefree
Math::GMPz->new(Math::Prime::Util::GMP::vecprod(map { Math::Prime::Util::GMP::subint($_, 1) } @$factors));
}
while (my ($key, $value) = each %$carmichael) {
# In 1980 Cohen and Hagis proved that, for any
# solution n to the problem, n > 10^20 and ω(n) ≥ 14.
next if (length($key) <= 20);
my @factors = split(' ', $value);
scalar(@factors) >= 14 or next;
my $n = Math::GMPz->new($key);
#say "Checking: $n";
my $phi = my_euler_phi(\@factors);
my $nm1 = $n - 1;
if (odd_part($nm1) == odd_part($phi)) {
die "[1] Counter-example: $n";
}
if (Math::GMPz::Rmpz_divisible_p($nm1, $phi)) {
die "[2] Counter-example: $n";
}
}
say "No counter-example found...";