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

Function modular_division2

maths/modular_division.py:63–79  ·  view source on GitHub ↗

This function used the above inversion of a to find x = (b*a^(-1))mod n >>> modular_division2(4,8,5) 2 >>> modular_division2(3,8,5) 1 >>> modular_division2(4, 11, 5) 4

(a: int, b: int, n: int)

Source from the content-addressed store, hash-verified

61
62
63def modular_division2(a: int, b: int, n: int) -> int:
64 """
65 This function used the above inversion of a to find x = (b*a^(-1))mod n
66
67 >>> modular_division2(4,8,5)
68 2
69
70 >>> modular_division2(3,8,5)
71 1
72
73 >>> modular_division2(4, 11, 5)
74 4
75
76 """
77 s = invert_modulo(a, n)
78 x = (b * s) % n
79 return x
80
81
82def extended_gcd(a: int, b: int) -> tuple[int, int, int]:

Callers

nothing calls this directly

Calls 1

invert_moduloFunction · 0.70

Tested by

no test coverage detected