-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.pl
101 lines (71 loc) · 2.24 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
95
96
97
98
99
100
101
#!/usr/bin/perl
# a(n) is the first number k such that k + a(i) is the product of n distinct prime factors, for all i < n; a(0) = 0.
# https://oeis.org/A??????
# Known terms:
# 0, 2, 33, 1309, 55165, 13386021, 2239003921
# Lower-bounds:
# a(7) > 1649267441663, if it exists.
use 5.036;
use ntheory qw(:all);
my @terms = (0, 2, 33, 1309, 55165, 13386021, 2239003921);
sub squarefree_almost_prime_numbers ($A, $B, $k, $callback) {
$A = vecmax($A, powint(2, $k));
my $n = $k;
sub ($m, $p, $k) {
if ($k == 1) {
my $v;
forprimes {
$v = $m * $_;
if ( is_almost_prime($n, $v + $terms[-1])
and is_almost_prime($n, $v + $terms[-2])
and is_almost_prime($n, $v + $terms[-3])
and is_square_free($v + $terms[-1])
and is_square_free($v + $terms[-2])
and is_square_free($v + $terms[-3])
and vecall { is_almost_prime($n, $v + $_) and is_square_free($v + $_) } @terms) {
$callback->($v);
$B = $v if ($v < $B);
lastfor;
}
} vecmax($p, cdivint($A, $m)), divint($B, $m);
return;
}
my $s = rootint(divint($B, $m), $k);
foreach my $q (@{primes($p, $s)}) {
__SUB__->($m * $q, $q+1, $k - 1);
}
}
->(1, 2, $k);
}
my $n = 7;
my $lo = 2;
my $hi = 2 * $lo;
say "\n:: Searching for a($n)\n";
while (1) {
say "Sieving: [$lo, $hi]";
my @terms;
squarefree_almost_prime_numbers(
$lo, $hi, $n,
sub($k) {
say "Found upper-bound: a($n) <= $k";
push @terms, $k;
}
);
@terms = sort { $a <=> $b } @terms;
if (@terms) {
say "New term: a($n) = $terms[0]\n";
last;
}
$lo = $hi + 1;
$hi = 2 * $lo;
}
__END__
Sieving: [805306367, 1610612734]
Sieving: [1610612735, 3221225470]
Found upper-bound: a(6) <= 2239003921
New term: a(6) = 2239003921
perl prog.pl 28.40s user 0.04s system 92% cpu 30.751 total
Sieving: [824633720831, 1649267441662]
Sieving: [1649267441663, 3298534883326]
^C
perl prog.pl 6250.60s user 14.21s system 84% cpu 2:03:41.07 total