almost_abundant_carmichael.pl 696 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/perl
  2. # Generate Carmichael numbers from other numbers, that are almost abundant, using a special multiplier.
  3. use 5.020;
  4. use strict;
  5. use warnings;
  6. use Math::Prime::Util::GMP qw(is_pseudoprime is_carmichael mulint divint vecprod gcd);
  7. my @primes = (3, 5, 17, 23, 29);
  8. #my @primes = (3, 5, 17);
  9. my $multiplier = vecprod(@primes);
  10. while (<>) {
  11. next if /^\h*#/;
  12. /\S/ or next;
  13. my $n = (split(' ', $_))[-1];
  14. my $g = gcd($n, $multiplier);
  15. if ($g > 1) {
  16. next if ($g == $multiplier);
  17. $n = divint($n, $g);
  18. }
  19. $n = mulint($n, $multiplier);
  20. $n > ~0 or next;
  21. #is_pseudoprime($n, 2) || next;
  22. is_carmichael($n) || next;
  23. say $n;
  24. }