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.
defcheck(li,c):ii=0flag=1smallestval=cforiinli:forjinli[ii:]:ifi==j:passelse:val=int(i)+int(j)ifsmallestval!=valandval>c:if(val<smallestvalandsmallestval!=c):smallestval=valifsmallestval==c:ifval>smallestval:smallestval=valii+=1f=0ii=0foriinli:forjinli[ii:]:ifint(i)+int(j)==smallestval:f+=1ii+=1iff==1:returnsmallestvalreturnck=1v1,k=raw_input("enter two numbers").split()ifint(v1)>=2andint(v1)<=10:ifint(k)>=1andint(k)<=10**11:v2=2*int(v1)+1li=[]li.append(v1)li.append(v2)li.append(int(v1)+int(v2))c=int(v1)+int(v2)whilelen(li)!=int(k):copy=cc=check(li,c)ifcopy==c:c+=1continueli.append(c)printli[int(k)-1]
it takes a bit long time, can anyone please let me know a better way to do it..
it worked for the first test case though.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #167: Investigating Ulam sequences
You are viewing a single comment's thread. Return to all comments →
it takes a bit long time, can anyone please let me know a better way to do it.. it worked for the first test case though.