Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Arithmetic-numbers/Perl/arithmetic-numbers.pl
Normal file
24
Task/Arithmetic-numbers/Perl/arithmetic-numbers.pl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use feature 'say';
|
||||
|
||||
use List::Util <max sum>;
|
||||
use ntheory <is_prime divisors>;
|
||||
use Lingua::EN::Numbers qw(num2en num2en_ordinal);
|
||||
|
||||
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
|
||||
sub table { my $t = 10 * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr }
|
||||
|
||||
my @A = 0;
|
||||
for my $n (1..2E6) {
|
||||
my @div = divisors $n;
|
||||
push @A, $n if 0 == sum(@div) % @div;
|
||||
}
|
||||
|
||||
say "The first @{[num2en 100]} arithmetic numbers:";
|
||||
say table @A[1..100];
|
||||
|
||||
for my $x (1E3, 1E4, 1E5, 1E6) {
|
||||
say "\nThe @{[num2en_ordinal $x]}: " . comma($A[$x]) .
|
||||
"\nComposite arithmetic numbers ≤ @{[comma $A[$x]]}: " . comma -1 + grep { not is_prime($_) } @A[1..$x];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue