boj1629-종이의 개수

먼지감자·2021년 6월 9일
0

코딩테스트

목록 보기
16/37

문제

https://www.acmicpc.net/problem/1629

코드 (152 ms)

import sys
from typing import Dict
input = sys.stdin.readline

A, B ,C = map(int, input().split())
# B 짝수일 경우 : (A^(B//2) ^2) % C
# B 홀수일 경우 : (A^(B//2) ^2)*A % C
def power(A,B):
    if B ==1:
        return A%C
    else:
        basic = power(A,B//2)
        if B % 2 ==0: 
            return int(basic*basic % C)
        else:
            return int(basic*basic*A % C)

print(power(A,B))

-출처 : https://jjangsungwon.tistory.com/10

profile
ML/AI Engineer

0개의 댓글