central_polygonal_carmichael.pl 642 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/perl
  2. # Carmichael numbers (A002997) that are central polygonal numbers (A002061).
  3. # https://oeis.org/A303791
  4. # Known terms:
  5. # 5310721, 2278677961, 9593125081, 29859667201, 467593730289953281
  6. use 5.020;
  7. use strict;
  8. use warnings;
  9. use Math::GMPz;
  10. use ntheory qw(:all);
  11. my $z = Math::GMPz::Rmpz_init();
  12. while (<>) {
  13. next if /^\h*#/;
  14. /\S/ or next;
  15. my $n = (split(' ', $_))[-1];
  16. $n || next;
  17. Math::GMPz::Rmpz_set_str($z, $n, 10);
  18. Math::GMPz::Rmpz_mul_2exp($z, $z, 2);
  19. Math::GMPz::Rmpz_sub_ui($z, $z, 3);
  20. if (Math::GMPz::Rmpz_perfect_square_p($z) and is_carmichael($n)) {
  21. say $n;
  22. }
  23. }