carmichael_in_range_cached.pl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/perl
  2. # List Carmichael numbers in a given range.
  3. # Problem from:
  4. # https://math.stackexchange.com/questions/4734978/how-can-we-find-a-carmichael-number-near-a-huge-given-number
  5. use 5.020;
  6. use strict;
  7. use warnings;
  8. use Storable;
  9. use Math::GMPz;
  10. use ntheory qw(:all);
  11. #use Math::Sidef qw(is_over_psp);
  12. use Math::Prime::Util::GMP;
  13. use experimental qw(signatures);
  14. my $carmichael_file = "cache/factors-carmichael.storable";
  15. my $carmichael = retrieve($carmichael_file);
  16. my $min = "9999999999999999999999999999796847326318726073975133650980786082646990292703172311852106037044385201";
  17. my $max = "10000000000000000000000000000090165987523064535571479173405047627125202459134286779355757424137024721";
  18. #my $min = "9999999999999999999999999995194780645298842465772438047052058885837645928421429394846343577780058169";
  19. #my $max = "10000000000000000000000000000405929367865700162694655745350302085810080768959837103297359653235421369";
  20. while(my($key, $value) = each %$carmichael) {
  21. if (
  22. Math::Prime::Util::GMP::cmpint($key, $min) > 0 and
  23. Math::Prime::Util::GMP::cmpint($key, $max) < 0
  24. ) {
  25. say $key;
  26. }
  27. }
  28. __END__