RosettaCodeData/Task/Modular-inverse/EasyLang/modular-inverse.easy

22 lines
270 B
Text
Raw Permalink Normal View History

2023-09-16 17:28:03 -07:00
func mod_inv a b .
2023-07-01 11:58:00 -04:00
b0 = b
x1 = 1
if b = 1
2023-09-16 17:28:03 -07:00
return 1
2023-07-01 11:58:00 -04:00
.
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
.
2023-09-16 17:28:03 -07:00
return x1
2023-07-01 11:58:00 -04:00
.
2023-09-16 17:28:03 -07:00
print mod_inv 42 2017