We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def collats(n):
if n==1:
return(1)
if n%2==1:
return(1+collats(3*n+1))
else:
return(1+collats(n/2))
for i in range(int(input())):
print(collats(int(input())))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #14: Longest Collatz sequence
You are viewing a single comment's thread. Return to all comments →
def collats(n): if n==1: return(1) if n%2==1: return(1+collats(3*n+1)) else: return(1+collats(n/2)) for i in range(int(input())): print(collats(int(input())))