Achilles numbers: Difference between revisions

m
→‎{{header|Perl}}: minor simplifications
(→‎{{header|Wren}}: Tidied and moved totient function to Math library as it's used quite often.)
m (→‎{{header|Perl}}: minor simplifications)
Line 2,604:
use feature <say current_sub>;
use experimental 'signatures';
use List::AllUtils <max head uniqint>;
use ntheory <is_square_free is_power euler_phi>;
use Math::AnyNum <:overload idiv is_power iroot ipow is_coprime>;
 
sub table { my $t = shift() * (my $c = 1 + length max @_); ( sprintf( ('%' . $c . 'd') x @_, @_) ) =~ s/.{1,$t}\K/\n/gr }
 
sub powerful_numbers ($n, $k = 2) {
Line 2,618:
__SUB__->($m * ipow($v, $r), $r - 1);
}
}->(1, 2 * $k - 1);
sort { $a <=> $b } @powerful;
}
 
my(@P, (@achilles, %Ahash, @strong);
my @P = uniqint @P, powerful_numbers(10**9, $_2) for 2..9; shift @P;
!is_power($_) and push @achilles, $_ and $Ahash{$_}++ for @P;
$Ahash{euler_phi $_} and push @strong, $_ for @achilles;
 
say "First 50 Achilles numbers:\n" . table 10, . table 10, head 50, @achilles;
say "First 30 strong Achilles numbers:\n" . table 10, head 30, @strong;
say "Number of Achilles numbers with:\n";
 
for my $l (2..9) {
for my $c; $l ==(2 length.. and $c++ for9) @achilles;{
my $c;
$l == length and $c++ for @achilles;
say "$l digits: $c";
}</syntaxhighlight>
2,747

edits