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.
importitertools,mathn=5*10**6answers=[0]*(n+1)foriteminitertools.combinations(range(1,int(n**0.5)+1,2),r=2):#implementing euclid's theorem, where sides are (s^2-t^2)/2, st, (s^2+t^2)/2 and s>t, s and t are odd coprime numbers. t=item[0]s=item[1]ifmath.gcd(s,t)==1:foriinrange(s*(s+t),n+1,s*(s+t)):#I don't have to worry about repeats like for any different s and t if I will get the same sides, cause for one triplet of sides only one primitive triplet will exist and they won't repeat and I can always add 1 in the line below.answers[i]+=1max_tri=0answer=0final_answers=[]#our answersforiinrange(0,n+1):value=answers[i]ifvalue>max_tri:answer=imax_tri=valuefinal_answers.append(answer)for_inrange(int(input())):n=int(input())print(final_answers[n])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #39: Integer right triangles
You are viewing a single comment's thread. Return to all comments →
100/- points python 3