We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c1c694e commit 626c177Copy full SHA for 626c177
Math/Fast Exponentiation with Mod/modulo_exponention.java
@@ -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