Skip to content

Commit 9a56ffd

Browse files
committed
first commit
0 parents  commit 9a56ffd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Applying extended-euclidean-algorithm on negative powered number to find their inverses

extended-euclidean-algorithm.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def mmi(a,power,m):
2+
m0 = m
3+
x0 = 0
4+
x1 = 1
5+
if m == 0:
6+
return 0
7+
while a > 1:
8+
# quotient
9+
q = a/m
10+
t = m
11+
# euclids theorem
12+
m= a%m
13+
a = t
14+
# back subs
15+
t = x0
16+
x0 = x1-(q*x0)
17+
x1 = t
18+
if x1 < 0:
19+
x1 += m0
20+
return x1
21+
22+
def main():
23+
base, power, mod = map(int, raw_input().strip().split(' '))
24+
print mmi(base, power, mod)
25+
26+
if __name__ == "__main__":
27+
main()

0 commit comments

Comments
 (0)