-
Notifications
You must be signed in to change notification settings - Fork 0
/
super_psp.pl
46 lines (32 loc) · 966 Bytes
/
super_psp.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
#!/usr/bin/perl
use 5.020;
use autodie;
use warnings;
use Math::GMPz;
use Storable;
use ntheory qw(:all);
use experimental qw(signatures);
eval { require GDBM_File };
my $cache_db = "/home/swampyx/Other/Programare/experimental-projects/pseudoprimes/programs/cache/factors.db";
dbmopen(my %cache_db, $cache_db, 0444)
or die "Can't create/access database <<$cache_db>>: $!";
sub is_super_pseudoprime ($n, $factors) {
my $gcd = Math::Prime::Util::GMP::gcd(map{ ($_ < ~0) ? ($_ - 1) : Math::Prime::Util::GMP::subint($_, 1) } split(' ', $factors));
Math::Prime::Util::GMP::powmod(2, $gcd, $n) eq '1';
}
#while (my ($key, $value) = each %cache_db) {
while (<>) {
/\S/ || next;
chomp;
my $n = $_;
$n > ~0 or next;
my $value = $cache_db{$n};
if (not defined $value) {
warn "# $n does not exist in the DB!\n";
next;
}
if (is_super_pseudoprime($n, $value)) {
say $n;
}
}
dbmclose(%cache_db);