Skip to content

Commit

Permalink
백준 14920 3n+1 수열 python init
Browse files Browse the repository at this point in the history
  • Loading branch information
dydwnsekd committed Dec 30, 2024
1 parent e236c01 commit f596ad1
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions baekjoon/python/14920.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@

n = int(sys.stdin.readline())

sequence_list = [n]

def sequence(num):
if num == 1:
return n
return sequence_list[0]
elif num % 2 == 1:
return sequence(sequence(num-1)//2)
return sequence_list[num-2] // 2
elif num % 2 == 0:
return 3 * sequence(num-1) + 1
return 3 * sequence_list[num-2] + 1

count = 1

sequence_list = [n]
print(sequence(2))

while True:
count += 1

sequence_list.append(sequence(count))

if sequence_list[count-1] == 1:
if sequence_list[count-1] % 100 == 1:
print(count)
break



0 comments on commit f596ad1

Please sign in to comment.