일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 백준
- Algorithm
- 영화
- usaco
- 2020
- 알고리즘
- coding
- 리뷰
- kakao
- 넷플릭스
- Netflix
- silver
- review
- 나는솔로
- 영어
- 해설
- benefits
- health
- parametric search
- BFS
- 수능
- 카카오
- 추천
- Greedy
- BOJ
- 코딩 테스트
- 완전탐색
- Movie
- array
- Recursive
Archives
- Today
- Total
Young
effective power function 본문
728x90
반응형
거듭제곱을 조금 더 효율적으로 하는 recursive 함수입니다.
시간 복잡도는 O(logN) 입니다.
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
|
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#define endl '\n'
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
ll power(int a, int b) {
if (b == 0) return 1;
if (b == 1) return a;
ll ret = power(a, b >> 1);
if (b & 1) return ret * ret * a;
return ret * ret;
}
int main() {
FastIO;
cout << power(2, 7) << endl;
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
728x90
반응형
'코딩 테스트 대비 추천 문제' 카테고리의 다른 글
정사각 배열 90도 회전 (0) | 2019.04.06 |
---|---|
BOJ - 배열 돌리기 2 (16927) (0) | 2019.04.06 |
소문난 칠공주 (0) | 2019.03.12 |
전공책 (0) | 2019.03.12 |
문자 메시지 (0) | 2019.03.11 |