steuerwald-ordowsk_theorem.pl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/perl
  2. # On Steuerwald's theorem (1948)
  3. # Tomasz Ordowsk:
  4. # Let m = (b^n-1)/(b-1).
  5. # Theorem: if m == 1 (mod n), then b^(m-1) == 1 (mod m).
  6. # Conjecture: if b^(m-1) == 1 (mod m), then m == 1 (mod n).
  7. # The conjecture is probably true. No counter-example is known.
  8. use 5.020;
  9. use strict;
  10. use warnings;
  11. use Math::GMPz;
  12. use ntheory qw(:all);
  13. my %seen;
  14. my $m = Math::GMPz::Rmpz_init();
  15. while (<>) {
  16. next if /^\h*#/;
  17. /\S/ or next;
  18. my $n = (split(' ', $_))[-1];
  19. $n || next;
  20. Math::GMPz::Rmpz_set_str($m, $n, 10);
  21. foreach my $b (2, 3, 5) {
  22. my $t = $m * ($b - 1) + 1;
  23. if (Math::GMPz::Rmpz_perfect_power_p($t)) {
  24. my $n = is_power($t);
  25. $n > 0 or next;
  26. say "Testing: n = $n and b = $b";
  27. if ($m % $n == 1) {
  28. next;
  29. }
  30. (Math::GMPz->new($b)**$n - 1) / ($b - 1) == $m
  31. or next;
  32. if (powmod($b, $m - 1, $m) == 1) {
  33. die "Counter example for $m with b = $b and n = $n";
  34. }
  35. }
  36. }
  37. }