safe_pseudoprimes.pl 449 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/perl
  2. # Try to find Fermat pseudoprimes P such that (P-1)/2 is prime.
  3. # No such pseudoprimes should exist.
  4. use 5.020;
  5. use strict;
  6. use warnings;
  7. use Math::Prime::Util::GMP qw(is_pseudoprime is_prob_prime subint divint);
  8. while (<>) {
  9. next if /^\h*#/;
  10. /\S/ or next;
  11. my $n = (split(' ', $_))[-1];
  12. $n || next;
  13. is_pseudoprime($n, 2) || next;
  14. if (is_prob_prime(divint(subint($n, 1), 2))) {
  15. say $n;
  16. }
  17. }