carmichael_lambda.pl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/perl
  2. # Carmichael numbers whose index is a power of 2
  3. # https://oeis.org/A306828
  4. # Known terms:
  5. # 7816642561, 49413980161, 32713826587115521
  6. use 5.020;
  7. use strict;
  8. use warnings;
  9. use experimental qw(signatures);
  10. use Math::GMPz;
  11. use ntheory qw(:all);
  12. use Math::AnyNum qw(is_smooth);
  13. sub odd_part ($n) {
  14. $n >> valuation($n, 2);
  15. }
  16. my @nums;
  17. while (<>) {
  18. next if /^\h*#/;
  19. /\S/ or next;
  20. my $n = (split(' ', $_))[-1];
  21. $n || next;
  22. next if $n < ~0;
  23. next if length($n) > 40;
  24. #~ next if length($n) <= 40;
  25. #~ next if length($n) > 45;
  26. #~ next if length($n) <= 45;
  27. #~ next if length($n) > 50;
  28. #~ next if length($n) <= 50;
  29. #~ next if length($n) > 55;
  30. #~ next if length($n) <= 40;
  31. #~ next if length($n) >= 55;
  32. #~ next if length($n) <= 55;
  33. if ($n > ((~0) >> 1)) {
  34. $n = Math::GMPz->new("$n");
  35. }
  36. push @nums, $n;
  37. }
  38. @nums = sort { $a <=> $b } @nums;
  39. say "There are ", scalar(@nums), " total numbers";
  40. foreach my $n (@nums) {
  41. is_pseudoprime($n, 2) || next;
  42. is_smooth($n - 1, 1e5) || next;
  43. is_carmichael($n) || next;
  44. my $odd = odd_part($n - 1);
  45. say "Testing: $n with $odd";
  46. if ($odd == odd_part(carmichael_lambda($n))) {
  47. say "Counter-example found: $n";
  48. sleep 2;
  49. if ($n > 32713826587115521) {
  50. die "New term for A306828: $n";
  51. }
  52. }
  53. if ($odd == odd_part(euler_phi($n))) {
  54. die "Lehmer's totient conjecture counter-example found: $n";
  55. }
  56. }