carmichael_m-1_is_square.pl 675 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/perl
  2. # Carmichael numbers n such that n-1 is a square.
  3. # https://oeis.org/A265285
  4. use 5.020;
  5. use strict;
  6. use warnings;
  7. use Math::GMPz;
  8. use ntheory qw(:all);
  9. my $z = Math::GMPz::Rmpz_init();
  10. my %seen;
  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_square_p($z) and is_carmichael($n)) {
  19. say $n if !$seen{$n}++;
  20. }
  21. }
  22. __END__
  23. 46657
  24. 2433601
  25. 67371265
  26. 351596817937
  27. 422240040001
  28. 18677955240001
  29. 458631349862401
  30. 286245437364810001
  31. 20717489165917230086401
  32. 520417541686202544384000001