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 STDOUTimportmathdefis_square(n):sqrt_n=int(math.sqrt(n))returnsqrt_n*sqrt_n==ndefminimal_solution(D):m,d,a=0,1,int(math.sqrt(D))num1,num2=1,aden1,den2=0,1whilenum2*num2-D*den2*den2!=1:m=d*a-md=(D-m*m)// da=(int(math.sqrt(D))+m)// dnum1,num2=num2,a*num2+num1den1,den2=den2,a*den2+den1returnnum2deflargest_minimal_solution(limit):max_D=0max_minimal_solution=0forDinrange(2,limit+1):ifnotis_square(D):solution=minimal_solution(D)ifsolution>max_minimal_solution:max_minimal_solution=solutionmax_D=Dreturnmax_D# Read input and calculate the resultlimit=int(input())result=largest_minimal_solution(limit)print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #66: Diophantine equation
You are viewing a single comment's thread. Return to all comments →
here is my python 3 100/- Point Solution