MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / extended_euclid

Function extended_euclid

maths/chinese_remainder_theorem.py:19–32  ·  view source on GitHub ↗

>>> extended_euclid(10, 6) (-1, 2) >>> extended_euclid(7, 5) (-2, 3)

(a: int, b: int)

Source from the content-addressed store, hash-verified

17
18# Extended Euclid
19def extended_euclid(a: int, b: int) -> tuple[int, int]:
20 """
21 >>> extended_euclid(10, 6)
22 (-1, 2)
23
24 >>> extended_euclid(7, 5)
25 (-2, 3)
26
27 """
28 if b == 0:
29 return (1, 0)
30 (x, y) = extended_euclid(b, a % b)
31 k = a // b
32 return (y, x - k * y)
33
34
35# Uses ExtendedEuclid to find inverses

Callers 2

invert_moduloFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected