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