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.
# Enter your code here. Read input from STDIN. Print output to STDOUTN,n1,n2=map(int,input().split())# dict acting like a dispatcher to calculate series valuel_n={3:lambdax:(x*(x+1))//2,5:lambdax:(x*(3*x-1))//2,6:lambdax:x*(2*x-1)}nc1,nc2=1,1# two counters to catch up the series without saving valuewhileTrue:val_n2,val_n1=l_n[n2](nc2),l_n[n1](nc1)''' compute for the higher order series and let the lower value series catch up '''whileval_n1<val_n2:nc1+=1val_n1=l_n[n1](nc1)ifval_n1>=N:breakifval_n1==val_n2:print(val_n1)nc2+=1
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #45: Triangular, pentagonal, and hexagonal
You are viewing a single comment's thread. Return to all comments →
python 100%