Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Prime-decomposition/Perl/prime-decomposition-1.pl
Normal file
9
Task/Prime-decomposition/Perl/prime-decomposition-1.pl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
sub prime_factors {
|
||||
my ($n, $d, @out) = (shift, 1);
|
||||
while ($n > 1 && $d++) {
|
||||
$n /= $d, push @out, $d until $n % $d;
|
||||
}
|
||||
@out
|
||||
}
|
||||
|
||||
print "@{[prime_factors(1001)]}\n";
|
||||
14
Task/Prime-decomposition/Perl/prime-decomposition-2.pl
Normal file
14
Task/Prime-decomposition/Perl/prime-decomposition-2.pl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
sub prime_factors {
|
||||
my($n, $p, @out) = (shift, 3);
|
||||
return if $n < 1;
|
||||
while (!($n&1)) { $n >>= 1; push @out, 2; }
|
||||
while ($n > 1 && $p*$p <= $n) {
|
||||
while ( ($n % $p) == 0) {
|
||||
$n /= $p;
|
||||
push @out, $p;
|
||||
}
|
||||
$p += 2;
|
||||
}
|
||||
push @out, $n if $n > 1;
|
||||
@out;
|
||||
}
|
||||
7
Task/Prime-decomposition/Perl/prime-decomposition-3.pl
Normal file
7
Task/Prime-decomposition/Perl/prime-decomposition-3.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
use ntheory qw/factor forprimes/;
|
||||
use bigint;
|
||||
|
||||
forprimes {
|
||||
my $p = 2 ** $_ - 1;
|
||||
print "2**$_-1: ", join(" ", factor($p)), "\n";
|
||||
} 100, 150;
|
||||
13
Task/Prime-decomposition/Perl/prime-decomposition-4.pl
Normal file
13
Task/Prime-decomposition/Perl/prime-decomposition-4.pl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use Math::Pari qw/:int factorint isprime/;
|
||||
|
||||
# Convert Math::Pari's format into simple vector
|
||||
sub factor {
|
||||
my ($pn,$pc) = @{Math::Pari::factorint(shift)};
|
||||
map { ($pn->[$_]) x $pc->[$_] } 0 .. $#$pn;
|
||||
}
|
||||
|
||||
for (100 .. 150) {
|
||||
next unless isprime($_);
|
||||
my $p = 2 ** $_ - 1;
|
||||
print "2^$_-1: ", join(" ", factor($p)), "\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue