prog.pl 611 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/perl
  2. # Numbers k such that (prime(k) - composite(k))/k is an integer, where prime(k) is the k-th prime.
  3. # https://oeis.org/A??????
  4. # Known terms:
  5. # 1, 3, 11, 43, 110283, 110316, 110356, 110374, 690076, 690084, 690374, 4427209, 11267500, 491071564,
  6. # PARI/GP program:
  7. # upto(n) = my(p=2, k=1); forcomposite(c=4, n, if((p-c)%k == 0, print1(k, ", ")); p=nextprime(p+1); k++);
  8. use 5.014;
  9. use integer;
  10. use ntheory qw(:all);
  11. my $k = 1;
  12. my $p = nth_prime($k);
  13. local $| = 1;
  14. forcomposites {
  15. if (($p - $_) % $k == 0) {
  16. print($k, ", ");
  17. }
  18. ++$k;
  19. $p = next_prime($p);
  20. } 1e9;