Skip to content

Commit 6bf9496

Browse files
authored
Create mmi.java
1 parent a8a6550 commit 6bf9496

File tree

1 file changed

+25
-0
lines changed
  • Math/modular_multiplicative_inverse

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Java program to find modular inverse
2+
// of a under modulo m
3+
import java.io.*;
4+
5+
class GFG {
6+
7+
// A naive method to find modulor
8+
// multiplicative inverse of 'a'
9+
// under modulo 'm'
10+
static int modInverse(int a, int m)
11+
{
12+
a = a % m;
13+
for (int x = 1; x < m; x++)
14+
if ((a * x) % m == 1)
15+
return x;
16+
return 1;
17+
}
18+
19+
// Driver Program
20+
public static void main(String args[])
21+
{
22+
int a = 3, m = 11;
23+
System.out.println(modInverse(a, m));
24+
}
25+
}

0 commit comments

Comments
 (0)