fermat_from_divisors.pl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/perl
  2. # Generate base-2 Fermat pseudoprimes 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**20;
  11. my $sigma0_limit = 2**17;
  12. while (<>) {
  13. next if /^\h*#/;
  14. /\S/ or next;
  15. my $n = (split(' ', $_))[-1];
  16. $n =~ /^[0-9]+\z/ || next;
  17. $n > ~0 or next;
  18. #length($n) > 45 or next;
  19. #$n = Math::GMPz->new($n);
  20. #$n % (3*5*17*23*29) == 0 or next;
  21. is_rough($n, 1e5) && next;
  22. if (length($n) > 45) {
  23. is_smooth($n, 1e7) || next;
  24. }
  25. divisor_sum($n, 0) <= $sigma0_limit or next;
  26. #divisor_sum($n, 0) <= 2**17 and next;
  27. $seen{$n} = 1;
  28. foreach my $d (Math::Prime::Util::GMP::divisors($n)) {
  29. $d > ~0 or next;
  30. next if exists $seen{$d};
  31. if (Math::Prime::Util::GMP::is_pseudoprime($d, 2) and !Math::Prime::Util::GMP::is_provable_prime($d)) {
  32. say $d if !$seen{$d}++;
  33. }
  34. }
  35. }