-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_primes_2.pl
67 lines (46 loc) · 1.17 KB
/
create_primes_2.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
#!/usr/bin/perl
use 5.014;
use Math::GMPz;
use ntheory qw(is_prime kronecker valuation primes factor);
while (<>) {
my ($n) = (split(' '))[-1] || next;
$n = Math::GMPz->new($n);
my $l = kronecker($n, 5);
my $t = $n - $l;
#~ foreach my $k(2..1000) {
#~ if (is_prime($t*$k + $l)) {
#~ say $t*$k + $l;
#~ }
#~ }
#~ say $n;
#~ foreach my $k(1..10) {
#~ if (is_prime(($t << $k) + $l)) {
#~ say (($t<<$k) + $l);
#~ }
#~ }
#~ foreach my $p(1..1000) {
#~ Math::GMPz::Rmpz_divisible_ui_p($t, $p) || next;
#~ my $w = $t+0;
#~ my $v = valuation($t, $p);
#~ for (1..$v) {
#~ $w /= $p;
#~ if (is_prime($w + $l)) {
#~ say $w + $l;
#~ }
#~ }
#~ }
say $n;
my $limit = (factor($t))[-1];
foreach my $p(2..$limit) {
my $w = $t+0;
while (Math::GMPz::Rmpz_divisible_ui_p($w, $p)) {
$w /= $p;
if (is_prime($w + 1)) {
say $w + 1;
}
if (is_prime($w - 1)) {
say $w - 1;
}
}
}
}