-
Notifications
You must be signed in to change notification settings - Fork 0
/
steuerwald-ordowsk_theorem.pl
executable file
·54 lines (37 loc) · 1.06 KB
/
steuerwald-ordowsk_theorem.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
#!/usr/bin/perl
# On Steuerwald's theorem (1948)
# Tomasz Ordowsk:
# Let m = (b^n-1)/(b-1).
# Theorem: if m == 1 (mod n), then b^(m-1) == 1 (mod m).
# Conjecture: if b^(m-1) == 1 (mod m), then m == 1 (mod n).
# The conjecture is probably true. No counter-example is known.
use 5.020;
use strict;
use warnings;
use Math::GMPz;
use ntheory qw(:all);
my %seen;
my $m = Math::GMPz::Rmpz_init();
while (<>) {
next if /^\h*#/;
/\S/ or next;
my $n = (split(' ', $_))[-1];
$n || next;
Math::GMPz::Rmpz_set_str($m, $n, 10);
foreach my $b (2, 3, 5) {
my $t = $m * ($b - 1) + 1;
if (Math::GMPz::Rmpz_perfect_power_p($t)) {
my $n = is_power($t);
$n > 0 or next;
say "Testing: n = $n and b = $b";
if ($m % $n == 1) {
next;
}
(Math::GMPz->new($b)**$n - 1) / ($b - 1) == $m
or next;
if (powmod($b, $m - 1, $m) == 1) {
die "Counter example for $m with b = $b and n = $n";
}
}
}
}