-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.pl
42 lines (30 loc) · 784 Bytes
/
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
#!/usr/bin/perl
# a(n) is the least k such that k^j+2 is prime for j = 1 to n but not n+1.
# https://oeis.org/A359396
# Known terms:
# 5, 9, 105, 3, 909, 4995825, 28212939
# a(8) > 10^11. - Lucas A. Brown, Jan 11 2023
use 5.014;
use strict;
use warnings;
use Math::GMPz;
use ntheory qw(:all);
my $n = 8;
my $z = Math::GMPz::Rmpz_init();
forprimes {
if (($_-2) % 3 == 0) {
my $count = 1;
my $j = 2;
my $m = $_-2;
while (1) {
Math::GMPz::Rmpz_ui_pow_ui($z, $m, $j);
Math::GMPz::Rmpz_add_ui($z, $z, 2);
Math::GMPz::Rmpz_probab_prime_p($z, 0) || last;
++$j;
++$count;
}
if ($count >= $n) {
die "a($count) = $m";
}
}
} 1e11, 1e13;