carmichael_m-1_is_power.pl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/perl
  2. # Carmichael numbers n such that n-1 is a perfect power.
  3. # https://oeis.org/A265328
  4. use 5.020;
  5. use strict;
  6. use warnings;
  7. use Math::GMPz;
  8. use ntheory qw(:all);
  9. my %seen;
  10. my $z = Math::GMPz::Rmpz_init();
  11. while (<>) {
  12. next if /^\h*#/;
  13. /\S/ or next;
  14. my $n = (split(' ', $_))[-1];
  15. $n || next;
  16. Math::GMPz::Rmpz_set_str($z, $n, 10);
  17. Math::GMPz::Rmpz_sub_ui($z, $z, 1);
  18. if (Math::GMPz::Rmpz_perfect_power_p($z) and is_carmichael($n)) {
  19. say $n if !$seen{$n}++;
  20. }
  21. #<<<
  22. #~ my $t = Math::GMPz->new($n)**4 + 1;
  23. #~ if (is_carmichael($t)) {
  24. #~ say $t if !$seen{$t}++;
  25. #~ }
  26. #>>>
  27. }
  28. __END__
  29. 1729
  30. 46657
  31. 2433601
  32. 2628073
  33. 19683001
  34. 67371265
  35. 110592000001
  36. 351596817937
  37. 422240040001
  38. 432081216001
  39. 2116874304001
  40. 3176523000001
  41. 18677955240001
  42. 458631349862401
  43. 286245437364810001
  44. 312328165704192001
  45. 12062716067698821000001
  46. 20717489165917230086401
  47. 211215936967181638848001
  48. 411354705193473163968001
  49. 14295706553536348081491001
  50. 520417541686202544384000001
  51. 32490089562753934948660824001
  52. 782293837499544845175052968001
  53. 611009032634107957276386802479001
  54. 26079495962445633235872174137208001
  55. 2612444951766966131992650907329921024001