Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
proc mulInv(a0, b0): int =
|
||||
var (a, b, x0) = (a0, b0, 0)
|
||||
result = 1
|
||||
if b == 1: return
|
||||
while a > 1:
|
||||
let q = a div b
|
||||
a = a mod b
|
||||
swap a, b
|
||||
result = result - q * x0
|
||||
swap x0, result
|
||||
if result < 0: result += b0
|
||||
|
||||
proc chineseRemainder[T](n, a: T): int =
|
||||
var prod = 1
|
||||
var sum = 0
|
||||
for x in n: prod *= x
|
||||
|
||||
for i in 0 .. <n.len:
|
||||
let p = prod div n[i]
|
||||
sum += a[i] * mulInv(p, n[i]) * p
|
||||
|
||||
sum mod prod
|
||||
|
||||
echo chineseRemainder([3,5,7], [2,3,2])
|
||||
Loading…
Add table
Add a link
Reference in a new issue