BOJ : https://www.acmicpc.net/problem/3943
gitHub : https://github.com/junho0956/Algorithm/blob/master/3943/3943/%EC%86%8C%EC%8A%A4.cpp
요구하는 그대로 따라가주면 되는 문제.
단, iostream을 사용할 것이라면 테스트케이스가 10만개이므로
ios::sync_with_stdio(false); 을 사용해주도록 하자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <cstdio>
#include <algorithm>
using namespace std;
#pragma warning(disable:4996)
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long n;
scanf("%lld", &n);
long long ans = 1;
while (n != 1) {
ans = max(ans, n);
if (n % 2) n = n * 3 + 1;
else n /= 2;
}
printf("%lld\n", ans);
}
return 0;
}
|
복습) 20.02.08
'algorithm > BOJ' 카테고리의 다른 글
BOJ 2447번 별 찍기 - 10 (0) | 2020.01.06 |
---|---|
BOJ 10844번 쉬운 계단 수 (0) | 2020.01.06 |
4673번 : 셀프넘버 - junnnho (0) | 2019.09.26 |
scpc 2019 예선 1차 2번 문제 : 공 굴리기 - Junnnho (0) | 2019.07.04 |
scpc 2019 예선 1차 1번 문제 : 오르락 내리락 - Junnnho (0) | 2019.07.04 |