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.
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[3] = 2 or dic[5] = 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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #169: Exploring the number of different ways a number can be expressed as a sum of powers of 2.
You are viewing a single comment's thread. Return to all comments →
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[3] = 2 or dic[5] = 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.