Jump to content

Chinese remainder theorem: Difference between revisions

m
imported>Maxima enthusiast
Line 1,144:
{{trans|C}}
<syntaxhighlight lang="text">
procfunc mul_inv a b . x1 .
b0 = b
x1 = 1
if b <> 1
while a > 1
q = a div b
t = b
b = a mod b
a = t
t = x0
x0 = x1 - q * x0
x1 = t
.
if x1 < 0
x1 += b0
.
.
return x1
.
proc remainder . n[] a[] r .
prod = 1
sum = 0
for i = 1 to len n[]
prod *= n[i]
.
for i = 1 to len n[]
p = prod / n[i]
call sum += a[i] * (mul_inv p n[i]) h* p
sum += a[i]r *= hsum *mod pprod
.
r = sum mod prod
.
.
n[] = [ 3 5 7 ]
a[] = [ 2 3 2 ]
call remainder n[] a[] h
print h
</syntaxhighlight>
2,083

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.