Notice
Recent Posts
Recent Comments
Link
«   2026/09   »
일 월 화 수 목 금 토
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 30
Tags more
Archives
Today
Total
관리 메뉴

seaking110 님의 블로그

1629번 곱셈 본문

오늘의 문제

1629번 곱셈

seaking110 2025. 1. 16. 11:45

 

문제 

 

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