-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.pl
94 lines (65 loc) · 1.98 KB
/
prog.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
#!/usr/bin/perl
# a(n) is the smallest k with n prime factors such that p^k == p (mod k) for every prime p dividing k.
# https://oeis.org/A294179
# Known terms:
# 2, 65, 561, 41041, 825265, 321197185
# Upper-bounds:
# a(7) <= 6295936465
# New terms found:
# a(7) = 5394826801
# a(8) = 232250619601
# Lower-bounds:
# a(9) > 4398046511105
use 5.020;
use strict;
use warnings;
use ntheory qw(:all);
use experimental qw(signatures);
use Math::Sidef qw(squarefree_almost_prime_count);
sub almost_prime_count_range ($n, $from, $upto) {
almost_prime_count($n, $upto) - almost_prime_count($n, $from-1);
}
sub divceil ($x,$y) { # ceil(x/y)
my $q = divint($x, $y);
(mulint($q, $y) == $x) ? $q : ($q+1);
}
sub squarefree_almost_primes ($A, $B, $k, $callback) {
$A = vecmax($A, pn_primorial($k));
sub ($m, $p, $k, $u = undef, $v = undef) {
if ($k == 1) {
forprimes {
$callback->(mulint($m, $_));
} $u, $v;
return;
}
my $s = rootint(divint($B, $m), $k);
while ($p <= $s) {
my $r = next_prime($p);
my $t = mulint($m, $p);
my $u = divceil($A, $t);
my $v = divint($B, $t);
if ($u <= $v) {
__SUB__->($t, $r, $k - 1, (($k==2 && $r>$u) ? $r : $u), $v);
}
$p = $r;
}
}->(1, 2, $k);
}
sub upper_bound($n, $from = 2, $upto = 2*$from) {
say "\n:: Searching an upper-bound for a($n)\n";
while (1) {
my $count = squarefree_almost_prime_count($n, $from, $upto);
if ($count > 0) {
say "Sieving range: [$from, $upto]";
say "This range contains: $count elements\n";
squarefree_almost_primes($from, $upto, $n, sub ($v) {
if (vecall {powmod($_, $v, $v) == $_} factor($v)) {
say "a($n) <= $v\n";
}
})
}
$from = $upto+1;
$upto *= 2;
}
}
upper_bound(9);