Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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";

View 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;
}

View 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;

View 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";
}