prog.pl 582 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. # a(n) is the first prime that starts a string of exactly n consecutive primes that are in A347702.
  3. # https://oeis.org/A356374
  4. # Known terms:
  5. # 131, 41, 11, 178909, 304290583, 8345111009
  6. use 5.010;
  7. use strict;
  8. use warnings;
  9. use ntheory qw(:all);
  10. my $n = 7;
  11. my $first;
  12. my $k = 0;
  13. forprimes {
  14. if ($_ % vecsum(split(//, $_)) == 1) {
  15. $first //= $_;
  16. ++$k;
  17. if ($k >= $n) {
  18. say "a($n) = ", $first;
  19. ++$n;
  20. }
  21. }
  22. elsif (defined($first)) {
  23. undef $first;
  24. $k = 0;
  25. }
  26. } 3*1e11, 1e12;