lucas-carmichael_conjecture.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/perl
  2. # Lucas-Carmichael numbers: squarefree composite numbers n such that p | n => p+1 | n+1.
  3. # It is not known whether any Lucas–Carmichael number is also a Carmichael number.
  4. # See also:
  5. # https://oeis.org/A006972
  6. # https://en.wikipedia.org/wiki/Lucas%E2%80%93Carmichael_number
  7. use 5.020;
  8. use strict;
  9. use warnings;
  10. use experimental qw(signatures);
  11. use Math::GMPz;
  12. use ntheory qw(:all);
  13. use Math::AnyNum qw(is_smooth);
  14. use Math::Prime::Util::GMP;
  15. my %seen;
  16. my @nums;
  17. sub is_lucas_carmichael_1 ($n) {
  18. my $t = $n + 1;
  19. vecall { $t % ($_ + 1) == 0 } Math::Prime::Util::GMP::factor($n);
  20. }
  21. sub is_lucas_carmichael_2 ($n) {
  22. vecprod(map { $_ - 1 } grep { is_prime($_ - 1) } map { Math::GMPz->new("$_") } Math::Prime::Util::GMP::divisors($n + 1)) % $n == 0;
  23. }
  24. while (<>) {
  25. next if /^\h*#/;
  26. /\S/ or next;
  27. my $n = (split(' ', $_))[-1];
  28. $n || next;
  29. next if $n < ~0;
  30. #next if ($n < ~0);
  31. Math::Prime::Util::GMP::is_pseudoprime($n, 2) || next;
  32. is_smooth($n, 1e5) || next;
  33. Math::Prime::Util::GMP::is_carmichael($n) || next;
  34. if ($n > ((~0) >> 1)) {
  35. $n = Math::GMPz->new("$n");
  36. }
  37. say "Testing: $n";
  38. is_lucas_carmichael_1($n) || next;
  39. die "Found counter-example: $n";
  40. }