216 Investigating the primality of numbers of the form 2.pl 363 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 18 August 2016
  4. # License: GPLv3
  5. # Website: https://github.com/trizen
  6. # https://projecteuler.net/problem=216
  7. # Runtime: 21.138s
  8. use 5.010;
  9. use strict;
  10. use integer;
  11. use ntheory qw(is_prime);
  12. my $p = 1;
  13. my $count = 0;
  14. for my $n (1 .. 50_000_000) {
  15. ++$count if is_prime($p += 4*$n+2);
  16. }
  17. say $count;