-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB1629.java
More file actions
29 lines (22 loc) · 735 Bytes
/
B1629.java
File metadata and controls
29 lines (22 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package Practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B1629 { //°ö¼À
static int A, B, C;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
A = Integer.parseInt(st.nextToken());
B = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
System.out.println(Solve(B) % C);
}
static long Solve(int n) {
if(n == 1) return A % C;
long num = Solve(n / 2);
if(n % 2 == 1) return (num * num % C) * A % C;
else return num * num % C;
}
}