odd_part_of_carmichael-1_is_carmichael.pl 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/perl
  2. # Thomas Ordowski, Oct 17 2015:
  3. # Are there Carmichael numbers k such that the odd part of k-1 is a Carmichael number?
  4. # https://oeis.org/A263403
  5. use 5.020;
  6. use strict;
  7. use warnings;
  8. use experimental qw(signatures);
  9. #use Math::GMPz;
  10. use ntheory qw(:all);
  11. use Math::Prime::Util::GMP;
  12. sub odd_part ($n) {
  13. #$n >> valuation($n, 2);
  14. #rshiftint($n, Math::Prime::Util::GMP::valuation($n, 2));
  15. Math::Prime::Util::GMP::divint($n, Math::Prime::Util::GMP::powint(2, Math::Prime::Util::GMP::valuation($n, 2)));
  16. }
  17. while (<>) {
  18. next if /^\h*#/;
  19. /\S/ or next;
  20. my $n = (split(' ', $_))[-1];
  21. $n || next;
  22. $n > ~0 or next;
  23. #~ if ($n > ((~0) >> 1)) {
  24. #~ $n = Math::GMPz->new("$n");
  25. #~ }
  26. if (Math::Prime::Util::GMP::is_carmichael(odd_part(Math::Prime::Util::GMP::subint($n, 1)))) {
  27. say "Candidate: $n";
  28. if (Math::Prime::Util::GMP::is_carmichael($n)) {
  29. die "Counter-example found: $n";
  30. }
  31. }
  32. }