-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudoprimes_testing.pl
59 lines (38 loc) · 1.05 KB
/
pseudoprimes_testing.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
#!/usr/bin/perl
# https://oeis.org/draft/A306479
use 5.014;
use ntheory qw(factor_exp vecprod forcomb forprimes vecmin is_square_free is_prime vecall factor);
#rad(n) = factorback(factorint(n)[, 1]);
#isok(n) = !isprime(n) && issquarefree(n) && select(x->factor(n-1)) == 1;
sub rad {
my ($n) = @_;
vecprod(map{$_->[0]}factor_exp($n));
}
my @files = glob("/home/swampyx/Other/Programare/Fun\\ scripts/Pseudoprimes/*.txt");
use Math::GMPz;
my @nums;
my %seen;
foreach my $file(@files) {
open my $fh, '<', $file;
while (<$fh>) {
/\S/ or next;
/^#/ and next;
my ($n) = (split(' '))[-1];
$n || next;
length($n) <= 25 or next;
next if $seen{$n}++;
push @nums, Math::GMPz->new($n);
}
close $fh;
}
say "Sorting...";
@nums = sort { $a <=> $b} @nums;
say "Searching...";
foreach my $n(@nums) {
is_prime($n) && next;
is_square_free($n) || next;
my $rad = rad($n-1);
if (vecall { rad($_-1) == $rad } factor($n)) {
say $n;
}
}