Skip to content

Commit 626c177

Browse files
author
Utkarsh Srivastava
committed
added java solution for modulo exponentiation
1 parent c1c694e commit 626c177

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.Scanner;
2+
3+
public class Power {
4+
public static int power(int x, int y, int p)
5+
{
6+
int ans = 1;
7+
x = x % p;
8+
9+
while (y > 0)
10+
{
11+
if((y & 1)==1)
12+
ans = (ans * x) % p;
13+
y = y >> 1;
14+
x = (x * x) % p;
15+
}
16+
return ans;
17+
}
18+
19+
20+
public static void main(String[] args) {
21+
Scanner sc = new Scanner(System.in);
22+
23+
int x = sc.nextInt();
24+
int y = sc.nextInt();
25+
int m = sc.nextInt();
26+
double ans = fast_expo(x, y, m);
27+
28+
System.out.println(ans);
29+
}
30+
}

0 commit comments

Comments
 (0)