Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Modular-inverse/Nim/modular-inverse.nim
Normal file
12
Task/Modular-inverse/Nim/modular-inverse.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
proc modInv(a0, b0: int): int =
|
||||
var (a, b, x0) = (a0, b0, 0)
|
||||
result = 1
|
||||
if b == 1: return
|
||||
while a > 1:
|
||||
result = result - (a div b) * x0
|
||||
a = a mod b
|
||||
swap a, b
|
||||
swap x0, result
|
||||
if result < 0: result += b0
|
||||
|
||||
echo modInv(42, 2017)
|
||||
Loading…
Add table
Add a link
Reference in a new issue