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.
Could make up my mind whether to use a formula or run through all Fibo numbers up to 5000 digits, so I did both:
importsyssys.set_int_max_str_digits(5010)fromdecimalimport*importrandomdeffib():a,b=1,1while...:yieldaa,b=b,a+bdefmain():# preload n[digits]n=[0]lastd=0fori,finenumerate(fib(),1):d=len(str(f))ifd>lastd:lastd=dn.append(i)ifd==5000:break# if d == 50: break# do queriesr5=Decimal(5**.5)lphi=Decimal((1+r5)/2).ln()for_inrange(int(input())):q=int(input())n_formula=(r5*10**(q-1)).ln()/lphiprint(random.choice([n_formula.to_integral_value(rounding=ROUND_CEILING),n[q]]))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 #25: N-digit Fibonacci number
You are viewing a single comment's thread. Return to all comments →
Could make up my mind whether to use a formula or run through all Fibo numbers up to 5000 digits, so I did both: