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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
def sol(n):
if n%2 == 1:
return n*3+1
else:
return n//2
if __name__ == '__main__':
n = int(input())
cnt = 0
while n!=1:
n = sol(n)
cnt+=1
print(cnt)
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
백준 5220 Error Detection (0) | 2023.01.04 |
---|---|
백준 16316 Baby Bites (0) | 2023.01.04 |
백준 16861 Harshad Numbers (0) | 2023.01.03 |
백준 23343 JavaScript (0) | 2023.01.03 |
백준 24267 알고리즘 수업 - 알고리즘의 수행 시간 6 (0) | 2023.01.03 |
댓글