File: project_euler_131.pl

package info (click to toggle)
libmath-prime-util-perl 0.73-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,796 kB
  • sloc: perl: 24,676; ansic: 11,471; makefile: 26; python: 24
file content (18 lines) | stat: -rw-r--r-- 398 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env perl
use warnings;
use strict;
use Math::Prime::Util qw/is_prime/;

my $limit = shift || 1000000;

# Any prime p where n^3 + n^2*p = m^3 must be the difference of (i+1)^3 - i^3.
# So we'll just walk them looking for primes.

my $sum = 0;
foreach my $i (1 .. 2650070) {
  my $j = $i+1;
  my $p = $j*$j*$j - $i*$i*$i;
  last if $p > $limit;
  $sum++ if is_prime($p);
}
print "$sum\n";