Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Modular-inverse/AWK/modular-inverse.awk
Normal file
27
Task/Modular-inverse/AWK/modular-inverse.awk
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# syntax: GAWK -f MODULAR_INVERSE.AWK
|
||||
# converted from C
|
||||
BEGIN {
|
||||
printf("%s\n",mod_inv(42,2017))
|
||||
exit(0)
|
||||
}
|
||||
function mod_inv(a,b, b0,t,q,x0,x1) {
|
||||
b0 = b
|
||||
x0 = 0
|
||||
x1 = 1
|
||||
if (b == 1) {
|
||||
return(1)
|
||||
}
|
||||
while (a > 1) {
|
||||
q = int(a / b)
|
||||
t = b
|
||||
b = int(a % b)
|
||||
a = t
|
||||
t = x0
|
||||
x0 = x1 - q * x0
|
||||
x1 = t
|
||||
}
|
||||
if (x1 < 0) {
|
||||
x1 += b0
|
||||
}
|
||||
return(x1)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue