[Python] 소프티어 LV.2_바이러스

szlee·2023년 11월 4일
0

알고리즘 PS

목록 보기
2/12

소프티어 LV.2_바이러스

쉽다고 생각했는데 10^8까지 가기 때문에 오버플로우 발생한다.

import sys


virus, p, n = map(int, sys.stdin.readline().rstrip().split())
print(virus*pow(p, n, 1000000007)%1000000007)

각 과정마다 1000000007을 충실히 나누어주어야하고,

python에서 math.pow와 pow도 다르다.
math.pow는 인자가 두개이고 math.pow(a, b) = a^b
pow는 인자 세개가 가능하고 pow(a, b, c) = a^b%c

https://deveun.tistory.com/entry/Python-%ED%8C%8C%EC%9D%B4%EC%8D%AC%EC%97%90%EC%84%9C-%EC%A0%9C%EA%B3%B1-%EA%B5%AC%ED%95%98%EA%B8%B0-pow-mathpow-%EC%9D%98-%EC%B0%A8%EC%9D%B4
https://hanseokhyeon.tistory.com/entry/%ED%8C%8C%EC%9D%B4%EC%8D%AC-pow-%ED%95%A8%EC%88%98

profile
🌱

0개의 댓글