Skip to content

Commit a5a0f55

Browse files
authored
Create modularMultiplicativeInverse.py
Given two integers ‘a’ and ‘m’, find modular multiplicative inverse of ‘a’ under modulo ‘m’. The modular multiplicative inverse is an integer ‘x’ such that. a x ≡ 1 (mod m) The value of x should be in {0, 1, 2, … m-1}, i.e., in the range of integer modulo m.
1 parent 8c85076 commit a5a0f55

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Python 3 program to find modular
2+
# inverse of a under modulo m
3+
4+
# A naive method to find modulor
5+
# multiplicative inverse of 'a'
6+
# under modulo 'm'
7+
def modInverse(a, m) :
8+
a = a % m;
9+
for x in range(1, m) :
10+
if ((a * x) % m == 1) :
11+
return x
12+
return 1
13+
14+
# Driver Program
15+
a = 3
16+
m = 11
17+
print(modInverse(a, m))
18+

0 commit comments

Comments
 (0)