[๋ฐฑ์ค-1629] ๊ณฑ์
/ Python
๐ Problem Solving/Baekjoon
1629๋ฒ: ๊ณฑ์
์ฒซ์งธ ์ค์ A, B, C๊ฐ ๋น ์นธ์ ์ฌ์ด์ ๋๊ณ ์์๋๋ก ์ฃผ์ด์ง๋ค. A, B, C๋ ๋ชจ๋ 2,147,483,647 ์ดํ์ ์์ฐ์์ด๋ค.
www.acmicpc.net
import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())
def func(length):
if length == 1:
return a % c
if length % 2 == 0:
temp = func(length // 2)
return temp * temp % c
else:
temp = func(length // 2)
return temp * temp * a % c
print(func(b))
ํด์ค
๊ธฐ๋ณธ ์ฐ์ฐ์ด๋ ๋ฐ๋ณต๋ฌธ์ผ๋ก ํ๋ฉด ์๊ฐ ์ด๊ณผ๊ฐ ๊ฑธ๋ฆฐ๋ค.
๋ถํ ์ ๋ณต์ ์ด์ฉํ์ฌ ํด๊ฒฐํ๋ค.
'๐ Problem Solving > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค-18353] ๋ณ์ฌ ๋ฐฐ์นํ๊ธฐ / Python (0) | 2021.06.04 |
---|---|
[๋ฐฑ์ค-2407] ์กฐํฉ / Python (0) | 2021.06.01 |
[๋ฐฑ์ค-1991] ํธ๋ฆฌ ์ํ / Python (0) | 2021.06.01 |
[๋ฐฑ์ค-16236] ์๊ธฐ ์์ด / Python (0) | 2021.05.31 |
[๋ฐฑ์ค-14500] ํ ํธ๋ก๋ฏธ๋ ธ / Python (0) | 2021.05.31 |