prog.pl 572 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/perl
  2. # Least number k such that both prime(k+1) -/+ prime(k) are products of n prime factors (counting multiplicity).
  3. # https://oeis.org/A288507
  4. use 5.014;
  5. use ntheory qw(factor prime_count forprimes next_prime nth_prime );
  6. #my $k = 1;
  7. my $k = 73268943890-100;
  8. my $p = nth_prime($k);
  9. my $n = 9;
  10. forprimes {
  11. my $q = $_;
  12. if (scalar(factor($p+$q)) == $n and $n == scalar(factor($q-$p))) {
  13. say "Found: ", prime_count($p), " with ", $p+$q, " and ", $q-$p, " with p = $p";
  14. ++$n;
  15. }
  16. $p = $_;
  17. #++$k;
  18. } next_prime($p), 1e13