-
Notifications
You must be signed in to change notification settings - Fork 0
/
n+1_divides_sigma(n)_db.pl
75 lines (51 loc) · 1.65 KB
/
n+1_divides_sigma(n)_db.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
#!/usr/bin/perl
# Try to find a squarefree number n such that n+1 | sigma(n).
# See also:
# https://math.stackexchange.com/questions/4576393/if-n-is-square-free-and-n1-mid-sigman-is-n-a-prime
# No counter-example found...
use 5.036;
use Storable;
use POSIX qw(ULONG_MAX);
use Math::GMPz;
use List::Util qw(uniq);
use ntheory qw(:all);
use Math::Prime::Util::GMP;
use experimental qw(signatures);
eval { require GDBM_File };
my $cache_db = "cache/factors.db";
dbmopen(my %db, $cache_db, 0444)
or die "Can't create/access database <<$cache_db>>: $!";
sub my_sigma ($factors) { # assumes n is squarefree
state $t = Math::GMPz::Rmpz_init();
state $u = Math::GMPz::Rmpz_init();
Math::GMPz::Rmpz_set_ui($t, 1);
foreach my $p (@$factors) {
if ($p < ULONG_MAX) {
Math::GMPz::Rmpz_mul_ui($t, $t, $p + 1);
}
else {
Math::GMPz::Rmpz_set_str($u, $p, 10);
Math::GMPz::Rmpz_add_ui($u, $u, 1);
Math::GMPz::Rmpz_mul($t, $t, $u);
}
}
return $t;
}
my $z = Math::GMPz::Rmpz_init();
my @results;
while (my ($key, $value) = each %db) {
Math::Prime::Util::GMP::modint($key, 4) == 3 or next;
my @factors = split(' ', $value);
scalar(@factors) >= 4 or next;
#$factors[-1] < ~0 or next;
my $sigma = my_sigma(\@factors);
Math::GMPz::Rmpz_set_str($z, $key, 10);
Math::GMPz::Rmpz_add_ui($z, $z, 1);
if (Math::GMPz::Rmpz_divisible_p($sigma, $z)) {
say "Almost counter-example: $z";
if (join(' ', @factors) eq join(' ', uniq(@factors))) {
die "Found counter-example: $z";
}
}
}
say "No counter-example found...";