Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Modular-inverse/PHP/modular-inverse.php
Normal file
16
Task/Modular-inverse/PHP/modular-inverse.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
function invmod($a,$n){
|
||||
if ($n < 0) $n = -$n;
|
||||
if ($a < 0) $a = $n - (-$a % $n);
|
||||
$t = 0; $nt = 1; $r = $n; $nr = $a % $n;
|
||||
while ($nr != 0) {
|
||||
$quot= intval($r/$nr);
|
||||
$tmp = $nt; $nt = $t - $quot*$nt; $t = $tmp;
|
||||
$tmp = $nr; $nr = $r - $quot*$nr; $r = $tmp;
|
||||
}
|
||||
if ($r > 1) return -1;
|
||||
if ($t < 0) $t += $n;
|
||||
return $t;
|
||||
}
|
||||
printf("%d\n", invmod(42, 2017));
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue