Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Team Fortress 2
- 그래프
- 재귀
- 그리디 알고리즘
- 알고리즘
- 투 포인터
- 수학
- 구현
- 유니온 파인드
- ue5
- 우선순위 큐
- 시뮬레이션
- 정렬
- 다익스트라
- BFS
- 자료구조
- 다이나믹 프로그래밍
- XR Interaction Toolkit
- c++
- 트리
- 유니티
- DFS
- 백준
- VR
- Unreal Engine 5
- 스택
- 누적 합
- 문자열
- 백트래킹
- 브루트포스
Archives
- Today
- Total
1일1알
백준 1629번 곱셈 C++ 본문

분할 정복을 이용하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int64 solve(int64 a, int64 b, int64 c) {
if (b == 1)
return a % c;
int64 tmp = solve(a, b / 2, c);
if (b % 2 == 0)
return tmp * tmp % c;
return ((tmp * tmp) % c * a) % c;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int64 a, b, c;
cin >> a >> b >> c;
cout << solve(a, b, c);
};
'알고리즘' 카테고리의 다른 글
백준 1916번 최소비용 구하기 C++ (0) | 2022.06.13 |
---|---|
백준 1991번 트리 순회 C++ (0) | 2022.06.12 |
백준 2407번 조합 C++ (0) | 2022.06.10 |
백준 1043번 거짓말 C++ (0) | 2022.06.09 |
백준 2504번 괄호의 값 C++ (0) | 2022.06.08 |