-
백준 1629 곱셈PS 2021. 4. 6. 05:51
<접근방법>
곱셈 + 큰 수 -> mod
<코드>
#include <iostream> #include <algorithm> using namespace std; long long ret(int a, int b, int c) { if (b == 0) return 1; long long half = ret(a, b / 2, c); if (b % 2 == 0) { return (half * half) % c; } else { return ((half * half) % c * a) % c; } } int main() { int a, b, c; cin >> a >> b >> c; cout << ret(a % c, b, c) << '\n'; return 0; }
반응형'PS' 카테고리의 다른 글
백준 13171 A (0) 2021.04.06 백준 17478 재귀함수가 뭔가요? (0) 2021.04.06 백준 1992번 쿼드트리 (0) 2021.04.04 백준 11729번 하노이 탑 이동순서 (0) 2021.04.02 백준 1074 Z (0) 2021.04.02