carmichael_from_divisors.pl 831 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/perl
  2. # Generate Carmichael numbers from the divisors of other numbers.
  3. use 5.020;
  4. use strict;
  5. use warnings;
  6. use ntheory qw(divisor_sum);
  7. use Math::Prime::Util::GMP;
  8. use Math::AnyNum qw(is_smooth is_rough);
  9. my %seen;
  10. my $sigma0_limit = 2**17;
  11. while (<>) {
  12. next if /^\h*#/;
  13. /\S/ or next;
  14. my $n = (split(' ', $_))[-1];
  15. $n =~ /^[0-9]+\z/ || next;
  16. $n > ~0 or next;
  17. #is_smooth($n, 1e6) || next;
  18. is_rough($n, 1e5) && next;
  19. if (length($n) > 45) {
  20. is_smooth($n, 1e7) || next;
  21. }
  22. divisor_sum($n, 0) <= $sigma0_limit or next;
  23. $seen{$n} = 1;
  24. foreach my $d (Math::Prime::Util::GMP::divisors($n)) {
  25. $d > ~0 or next;
  26. next if exists $seen{$d};
  27. if (Math::Prime::Util::GMP::is_carmichael($d)) {
  28. say $d if !$seen{$d}++;
  29. }
  30. }
  31. }