File: project_euler_214.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 (21 lines) | stat: -rw-r--r-- 370 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env perl
use warnings;
use strict;
use Math::Prime::Util qw/forprimes euler_phi/;

my $limit = shift || 40000000;
my $cl = shift || 25;

my @c;
sub totchainlen {
  my $n = shift;
  return $n if $n <= 2;
  $c[$n] //= 1 + totchainlen(euler_phi($n));
  return $c[$n];
}

my $sum = 0;
forprimes {
  $sum += $_ if totchainlen($_) == $cl;
} $limit;
print "$sum\n";