-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinverse_sigma.pl
163 lines (123 loc) · 3.07 KB
/
inverse_sigma.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/perl
# Least k such that k is the product of n distinct primes and sigma(k) is an n-th power.
# https://oeis.org/A281140
# a(14) <= 94467020965716904490370
use utf8;
use 5.020;
use strict;
use warnings;
use Math::GMPz;
use ntheory qw(:all);
use experimental qw(signatures);
sub dynamicPreimage ($N, $L) {
if (ref($N)) {
$N = Math::GMPz->new("$N");
}
my %r = (1 => [1]);
foreach my $l (@$L) {
my %t;
foreach my $pair (@$l) {
my ($x, $y) = @$pair;
fordivisors {
my $d = $_;
if (exists $r{$d}) {
push @{$t{mulint($x, $d)}}, map { mulint($_, $y) } @{$r{$d}};
}
} divint($N, $x);
}
while (my ($k, $v) = each %t) {
push @{$r{$k}}, @$v;
}
}
return if not exists $r{$N};
$r{$N};
}
sub dynamicPreimageLen ($N, $L) {
if (ref($N)) {
$N = Math::GMPz->new("$N");
}
my %r = (1 => 1);
foreach my $l (@$L) {
my %t;
foreach my $pair (@$l) {
my ($x, $y) = @$pair;
fordivisors {
my $d = $_;
if (exists $r{$d}) {
my $key = mulint($x, $d);
$t{$key} //= 0;
$t{$key} += $r{$d};
}
} divint($N, $x);
}
while (my ($k, $v) = each %t) {
$r{$k} //= 0;
$r{$k} += $v;
}
}
$r{$N} // 0;
}
sub cook_sigma ($N, $k) {
my %L;
fordivisors {
my $d = $_;
if ($d == 1) {
## ok
}
else {
foreach my $p (map { $_->[0] } factor_exp(subint($d, 1))) {
my $q = addint(mulint($d, subint(powint($p, $k), 1)), 1);
my $t = valuation($q, $p);
if (ref($q)) {
$q = Math::GMPz->new("$q");
}
if ($t <= $k or ($t % $k) or $q != powint($p, $t)) {
## ok
}
else {
push @{$L{$p}}, [$d, powint($p, subint(divint($t, $k), 1))];
}
}
}
}
$N;
[values %L];
}
sub inverse_sigma ($N, $k = 1) {
dynamicPreimage($N, cook_sigma($N, $k));
}
sub inverse_sigma_len ($N, $k = 1) {
dynamicPreimageLen($N, cook_sigma($N, $k));
}
sub a ($n) {
my @list;
foreach my $k (2 .. 1e9) {
is_smooth($k, 3) || next;
inverse_sigma_len(powint($k, $n)) <= 2e6 or next;
my $solutions = inverse_sigma(powint($k, $n)) // next;
foreach my $v (@$solutions) {
if (is_square_free($v) and is_almost_prime($n, $v)) {
push @list, $v;
}
}
last if @list;
}
vecmin(@list);
}
foreach my $n (1 .. 20) {
say "a($n) <= ", a($n);
}
__END__
a(1) <= 2
a(2) <= 22
a(3) <= 102
a(4) <= 510
a(5) <= 90510
a(6) <= 995610
a(7) <= 11616990
a(8) <= 130258590
a(9) <= 1483974030
a(10) <= 18404105922510
a(11) <= 428454465915630
a(12) <= 10195374973815570
a(13) <= 240871269907008510