File: project_euler_131.pl

package info (click to toggle)
libmath-prime-util-perl 0.46-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,044 kB
  • ctags: 1,933
  • sloc: perl: 19,450; ansic: 6,379; python: 24; makefile: 11
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";