-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pl
68 lines (50 loc) · 1.34 KB
/
test.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
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use Math::GMPz;
use ntheory qw(powmod rootint next_prime);
my $max = 0;
sub is_provable_prime {
my ($n) = @_;
return 1 if $n == 2;
return 0 if powmod(2, $n - 1, $n) != 1;
# Probably, we can improve this limit even further
my $limit = rootint($n, 3);
#(n/log(n,2)).iroot(3)
#my $limit = rootint(int($n/ntheory::logint($n, 2)), 3);
my $count = 0;
for (my $p = 3 ; $p <= $limit ; $p = next_prime($p)) {
++$count;
powmod($p, $n - 1, $n) != 1 and do {
if ($count > $max) {
$max = $count;
say "$n -> $count (p=$p ; limit=$limit) -- ", $p / $limit;
}
return 0;
}
}
return 1;
}
my %seen;
my @nums;
while (<>) {
next if /^\h*#/;
/\S/ or next;
my $n = (split(' ', $_))[-1];
$n || next;
next if $seen{$n}++;
#say $. if $. % 10000 == 0;
if ($n >= (~0 >> 1)) {
$n = Math::GMPz->new("$n");
}
push @nums, $n;
#is_provable_prime($n) && die "error: $n\n";
#ntheory::is_prime($n) && die "error: $n\n";
#ntheory::is_aks_prime($n) && die "error: $n\n";
#ntheory::miller_rabin_random($n, 7) && die "error: $n\n";
}
@nums = sort { $a <=> $b } @nums;
foreach my $n (@nums) {
is_provable_prime($n) && warn "error: $n\n";
}