seaking110 님의 블로그
1629번 곱셈 본문
문제

https://www.acmicpc.net/problem/1629
문제 풀이
public class Main {
public static StringBuilder sb = new StringBuilder();
public static int [] count = new int[3];
public static int arr [][];
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
long a = Long.parseLong(st.nextToken());
long b = Long.parseLong(st.nextToken());
long c = Long.parseLong(st.nextToken());
System.out.println(pow(a,b,c));
}
public static long pow(long a, long b, long c) {
if (b == 1) {
return a % c;
}
long res = pow(a, b/2, c);
if (b % 2 == 0) {
return res * res % c;
}
else {
return (res * res % c) * a % c;
}
}
}'오늘의 문제' 카테고리의 다른 글
| 10830번 행렬 제곱 (0) | 2025.01.21 |
|---|---|
| 2740번 행렬 곱셈 (0) | 2025.01.17 |
| 1780번 종이의 개수 (0) | 2025.01.15 |
| 1992번 퀴드트리 (0) | 2025.01.14 |
| 14889번 : 스타트와 링크 (1) | 2025.01.13 |