Sort 29 Discussions, By:
Please Login in order to post a comment
My math sucks but I still figure out how to do this. Search Stern's Diatomics Series and try to understand it. For those friends who have timeout problem in python, try to build up a dictionary and extend it as far as you can(remember dic[2**N] = 1 for diatomic series) and add few more other elements like dic = 2 or dic = 3. Recursively use the function and remember to update your dic everytime(important, otherwise timeout). You should see that you program solve all cases in seconds.
How would you do this in a language like C++, where there is no simple way to store an integer value of 10^27? Please advise.
I was wondering should the
fn(10) be 12
I dont understand what I am doing wrong here
just figure out // is floor division and / is float division.
When n are very large, / will round your result and // will result in integer.
Try the following code to see the difference
print(10 ** 25 / 2, 10 ** 25 // 2)
Can be solved more efficiently by dynamic programming.