File: project_euler_070.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-- 476 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/:all/;

sub is_perm {
  my($a,$b) = @_;
  return length($a) == length($b) &&
         join("",sort split(//,$a)) eq join("",sort split(//,$b));
}

my ($maxn, $minratio, $totient, $ratio) = (0, 1000000);
foreach my $n (2 .. 10_000_000) {
  $totient = euler_phi($n);
  $ratio = $n / $totient;
  ($maxn, $minratio) = ($n, $ratio) if $ratio < $minratio && is_perm($totient, $n);
}
print "$maxn  $minratio\n";