-
Notifications
You must be signed in to change notification settings - Fork 0
/
wieferich_primes_cached.pl
executable file
·73 lines (50 loc) · 1.53 KB
/
wieferich_primes_cached.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
#!/usr/bin/perl
# https://en.wikipedia.org/wiki/Wieferich_prime
# See also:
# https://oeis.org/A001220 -- Wieferich primes: primes p such that p^2 divides 2^(p-1) - 1.
# https://oeis.org/A039951 -- Smallest prime p such that p^2 divides n^(p-1) - 1.
use 5.020;
use strict;
use warnings;
use Math::GMPz;
use ntheory qw(:all);
use Math::Prime::Util::GMP;
use experimental qw(signatures);
#my $storable_file = "cache/factors-fermat.storable";
#my $storable_file = "cache/factors-lucas-carmichael.storable";
#my $fermat = retrieve($storable_file);
eval { require GDBM_File };
my $cache_db = "cache/factors.db";
dbmopen(my %db, $cache_db, 0444)
or die "Can't create/access database <<$cache_db>>: $!";
my $base = 2;
my $lim = 1250000000000000;
#~ my $base = 5;
#~ my $lim = 970000000000000;
#~ my $base = 6;
#~ my $lim = 41190000000000;
#~ my $base = 7;
#~ my $lim = 970000000000000;
#~ my $base = 10;
#~ my $lim = 117200000000000;
#~ my $base = 47;
#~ my $lim = 49000000000000;
#~ my $base = 15;
#~ my $lim = 50000000000000;
#~ my $base = 17;
#~ my $lim = 100000000000000;
#~ my $base = 23;
#~ my $lim = 31270000000000;
#~ my $base = 30;
#~ my $lim = 98000000000000;
while (my ($key, $value) = each %db) {
my @factors = split(' ', $value);
next if $factors[-1] < $lim;
foreach my $p (@factors) {
if ($p > $lim
and Math::Prime::Util::GMP::powmod($base, Math::Prime::Util::GMP::subint($p, 1), Math::Prime::Util::GMP::mulint($p, $p)) eq '1') {
say "\nFound: $p\n";
}
}
}
dbmclose(%db);