search.pl 750 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/perl
  2. # Primes p such that the sum of squares of primes < p is divisible by p.
  3. # https://oeis.org/A338818
  4. # Known terms:
  5. # 2, 13, 59, 118259, 182603
  6. # The next term, if it exists, is greater than 2^32.
  7. use 5.014;
  8. #use Primesieve;
  9. use ntheory qw(forprimes);
  10. use Math::Prime::Util::GMP qw(:all);
  11. use Math::GMPz;
  12. my $t = Math::GMPz::Rmpz_init_set_ui(0);
  13. my $sum = Math::GMPz::Rmpz_init_set_ui(0);
  14. forprimes {
  15. if (Math::GMPz::Rmpz_divisible_ui_p($sum, $_)) {
  16. say $_;
  17. }
  18. if ($_ < sqrt(~0)) {
  19. Math::GMPz::Rmpz_add_ui($sum, $sum, $_*$_);
  20. }
  21. else {
  22. Math::GMPz::Rmpz_set_ui($t, $_);
  23. Math::GMPz::Rmpz_mul($t, $t, $t);
  24. Math::GMPz::Rmpz_add($sum, $sum, $t);
  25. }
  26. } 2, 252097800623;