Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,9 @@
use bigint; say 42->bmodinv(2017);
# or
use Math::ModInt qw/mod/; say mod(42, 2017)->inverse->residue;
# or
use Math::Pari qw/PARI lift/; say lift PARI "Mod(1/42,2017)";
# or
use Math::GMP qw/:constant/; say 42->bmodinv(2017);
# or
use ntheory qw/invmod/; say invmod(42, 2017);

View file

@ -0,0 +1,15 @@
sub invmod {
my($a,$n) = @_;
my($t,$nt,$r,$nr) = (0, 1, $n, $a % $n);
while ($nr != 0) {
# Use this instead of int($r/$nr) to get exact unsigned integer answers
my $quot = int( ($r - ($r % $nr)) / $nr );
($nt,$t) = ($t-$quot*$nt,$nt);
($nr,$r) = ($r-$quot*$nr,$nr);
}
return if $r > 1;
$t += $n if $t < 0;
$t;
}
say invmod(42,2017);