문제 링크입니다: https://www.acmicpc.net/problem/6190
6190번: Another Cow Number Game
The cows are playing a silly number game again. Bessie is tired of losing and wants you to help her cheat. In this game, a cow supplies a number N (1 <= N <= 1,000,000). This is move 0. If N is odd, then the number N is multiplied by 3 and incremented by 1
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
long long N; | |
cin >> N; | |
int score = 0; | |
while (N != 1) | |
{ | |
if (N % 2) | |
{ | |
N = 3 * N + 1; | |
} | |
else | |
{ | |
N /= 2; | |
} | |
score++; | |
} | |
cout << score << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
BOJ 6322번 직각 삼각형의 두 변 (0) | 2021.05.31 |
---|---|
백준 6249번 TV Reports (0) | 2021.05.30 |
백준 6162번 Superlatives (0) | 2021.05.29 |
백준 6139번 Speed Reading (0) | 2021.05.29 |
백준 6131번 완전 제곱수 (0) | 2021.05.29 |