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

Function invert_modulo

maths/modular_division.py:43–57  ·  view source on GitHub ↗

This function find the inverses of a i.e., a^(-1) >>> invert_modulo(2, 5) 3 >>> invert_modulo(8,7) 1

(a: int, n: int)

Source from the content-addressed store, hash-verified

41
42
43def invert_modulo(a: int, n: int) -> int:
44 """
45 This function find the inverses of a i.e., a^(-1)
46
47 >>> invert_modulo(2, 5)
48 3
49
50 >>> invert_modulo(8,7)
51 1
52
53 """
54 (b, _x) = extended_euclid(a, n) # Implemented below
55 if b < 0:
56 b = (b % n + n) % n
57 return b
58
59
60# ------------------ Finding Modular division using invert_modulo -------------------

Callers 1

modular_division2Function · 0.70

Calls 1

extended_euclidFunction · 0.70

Tested by

no test coverage detected