-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudoprime_search.pl
117 lines (84 loc) · 1.94 KB
/
pseudoprime_search.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl
use 5.020;
use warnings;
use strict;
use ntheory qw(:all);
use experimental qw(signatures);
use List::Util qw(uniqnum);
use File::Find qw(find);
use Math::GMPz;
# Let b(n) be the smallest odd composite k such that q^((k-1)/2) == -1 (mod k) for every prime q <= prime(n).
# b(1) = 3277
# b(2) = 1530787
# b(3) = 3697278427
# b(4) = 118670087467
# b(5) <= 2152302898747
# b(6) <= 614796634515444067
# b(7) <= 614796634515444067
# 341, 1729, 1729, 46657
my $N = 6;
my $P = nth_prime($N);
my $MAX = ~0;
my @primes_bellow = @{primes($P)};
my @primes = @{primes(100)};
sub non_residue {
my ($n) = @_;
foreach my $p (@primes) {
if ($p > $P) {
return -1;
}
sqrtmod($p, $n) // return $p;
}
return -1;
}
sub isok_b {
my ($k) = @_;
#$k % 2 == 1 or return;
vecall { powmod($_, ($k-1)>>1, $k) == $k-1 } @primes_bellow;
}
sub isok_b2 {
my ($k) = @_;
$k % 2 == 1 or return;
vecall { powmod($_, ($k-1)>>1, $k) == 1 } 2..($P-1);
}
my %seen;
sub process_file {
my ($file) = @_;
open my $fh, '<', $file;
while (<$fh>) {
next if /^\h*#/;
/\S/ or next;
my $n = (split(' ', $_))[-1];
$n || next;
#if ($n > $MAX or $n <= 2) {
# next;
#}
if ($n < ~0) {
next;
}
if ($n > ~0) {
$n = Math::GMPz->new("$n");
}
next if is_prime($n);
next if $seen{$n}++;
#if (isok_b($n)) {
if (isok_b($n)) {
say "Found: $n";
#~ if ($n < $MAX) {
#~ $MAX = $n;
#~ say "New record: $n";
#~ }
}
}
close $fh;
}
my $psp = "/home/swampyx/Other/Programare/experimental-projects/pseudoprimes/oeis-pseudoprimes";
find({
wanted => sub {
if ( /\.txt\z/) {
#say "Processing $_";
process_file($_);
}
},
no_chdir => 1,
} => $psp);