Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions maths/modular_division.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ def modular_division(a: int, b: int, n: int) -> int:
4

"""
assert n > 1
assert a > 0
assert greatest_common_divisor(a, n) == 1
if n <= 1:
raise ValueError("Modulus n must be greater than 1")
if a <= 0:
raise ValueError("Divisor a must be a positive integer")
if greatest_common_divisor(a, n) != 1:
raise ValueError("a and n must be coprime (gcd(a, n) = 1)")

(_d, _t, s) = extended_gcd(n, a) # Implemented below
x = (b * s) % n
return x
Expand Down