-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.pl
69 lines (52 loc) · 1.23 KB
/
new.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
#!/usr/bin/perl
# Prime(n), where n is such that (sum_{i=1..n} prime(i)) / n is an integer.
# https://oeis.org/A171399
use 5.014;
use Math::GMPz;
use ntheory qw(next_prime);
sub prime_count {
my ($n) = @_;
chomp(my $p = `../primecount $n`);
return $p;
}
{
my $prev_i;
my $prev_p;
sub nth_prime {
my ($n) = @_;
if (not(defined($prev_i))) {
$prev_i = $n;
chomp($prev_p = `../primecount -n $n`);
return $prev_p;
}
for (1 .. $n - $prev_i) {
$prev_p = next_prime($prev_p);
}
$prev_i = $n;
return $prev_p;
}
}
{
my $prev_n;
my $prev_sum;
sub sum_primes {
my ($n) = @_;
if (not defined($prev_n)) {
chomp(my $sum = `../primesum $n`);
$prev_n = $n;
$prev_sum = Math::GMPz->new($sum);
return $prev_sum;
}
$prev_sum += ntheory::sum_primes($prev_n + 1, $n);
$prev_n = $n;
return $prev_sum;
}
}
for (my $n = prime_count("22128836547913") + 1 ; ; ++$n) {
say "Testing: $n";
my $p = nth_prime($n);
my $sum = sum_primes($p);
if ($sum % $n == 0) {
die "Found: $p with $sum % $n\n";
}
}