reversible_pseudoprimes.pl 570 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/perl
  2. # Find a pair of distinct reversible psp(2) other than 15709 & 90751.
  3. # See also:
  4. # https://www.primepuzzles.net/puzzles/puzz_170.htm
  5. use 5.020;
  6. use strict;
  7. use warnings;
  8. use ntheory qw(:all);
  9. my %seen;
  10. while (<>) {
  11. next if /^\h*#/;
  12. /\S/ or next;
  13. my $n = (split(' ', $_))[-1];
  14. $n || next;
  15. my $m = reverse($n);
  16. if ($m < $n) {
  17. ($n, $m) = ($m, $n);
  18. }
  19. if (is_pseudoprime($m, 2) and is_pseudoprime($n, 2) and !is_prime($m) and !is_prime($n) and $n ne $m) {
  20. say($n, " ", $m) if !$seen{$n}++;
  21. }
  22. }