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.
importmathdefperf_arc(n):root=int(math.sqrt(n))ifroot*root==n:return0a=1listaint=[root]den=n-root*rootlista_inv_frac=[(math.sqrt(n)+root)/den]per=0whileTrue:part_int=int(lista_inv_frac[-1])root=(den*part_int)// a - roota=den// aden=n-root*rootinvfrac=a*(math.sqrt(n)+root)/denlistaint.append(part_int)lista_inv_frac.append(invfrac)per+=1ifinvfrac==lista_inv_frac[0]:returnperdefmain():n=int(input())cnt_odd=0forkinrange(2,n+1):ifperf_arc(k)%2==1:cnt_odd+=1print(cnt_odd)if__name__=="__main__":main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #64: Odd period square roots
You are viewing a single comment's thread. Return to all comments →
python3 code 100points/-