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

Function extended_euclid

maths/modular_division.py:112–126  ·  view source on GitHub ↗

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

(a: int, b: int)

Source from the content-addressed store, hash-verified

110
111
112def extended_euclid(a: int, b: int) -> tuple[int, int]:
113 """
114 Extended Euclid
115 >>> extended_euclid(10, 6)
116 (-1, 2)
117
118 >>> extended_euclid(7, 5)
119 (-2, 3)
120
121 """
122 if b == 0:
123 return (1, 0)
124 (x, y) = extended_euclid(b, a % b)
125 k = a // b
126 return (y, x - k * y)
127
128
129def greatest_common_divisor(a: int, b: int) -> int:

Callers 1

invert_moduloFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected