You are viewing a single comment's thread. Return to all comments →
import array tot=[False]*5*10**6 tot=array.array("Q",tot) def fun(i): to=0 tem=i while(i!=1): if (i>5*10**6): if(i%2==0): i=i/2 to+=1 else: i=(3*i)+1 to+=1 elif(i<5*10**6): if(not tot[int(i)]): if(i%2==0): i=i/2 to+=1 else: i=(3*i)+1 to+=1 else: to+=tot[int(i)]-1 i=1 tot[int(tem)]=to+1 return(to) for i in range(1,5*10**6): fun(i) print("done") tem=[0]*5*10**6 mi=tem[1] index=1 for i in range(1,5*10**6): if(tot[i]>mi): mi=tot[i] index=i tem[i]=index else: tem[i]=index print("done 2") num=int(input()) for i in range(num): n=int(input()) print(tem[n])
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 →