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.
Can easily be done using Python in ~3s for each TC without caring about integer length (because this is PAINFUL):
Memoization is the key here:
Precompute fibonacci until you reach a number with 5000 digits
DON'T SAVE ALL FIBO NUMBERS
Save the fibo index each time you increase the max size
You now have an array of 5000 elements (each containing the right index) in about 3 seconds
Hint : Use string length while searching for integer length
for each test case, just print array[test_case]
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 →
Can easily be done using Python in ~3s for each TC without caring about integer length (because this is PAINFUL):
Memoization is the key here: Precompute fibonacci until you reach a number with 5000 digits DON'T SAVE ALL FIBO NUMBERS Save the fibo index each time you increase the max size You now have an array of 5000 elements (each containing the right index) in about 3 seconds
Hint : Use string length while searching for integer length
for each test case, just print array[test_case]