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.
This problem is obscenely difficult, and I spent days researching just to get fairly close to the correct solution, then I spent days more tweaking my approach to conform to the extra constraints created by the problem itself. In order to complete this in a reasonable time, you have to dig into number theory by realizing that, at least for a=1 to b=(some number of consecutive 9's), the problem resembles a permutation problem (since we take the sums/squares of these numbers, the question becomes 'how many combinations of k digits result in a prime number between 1 and 999999999999999999 when (summed) or (squared)?' and 'how can you exclude permutations that are less than a, and greater than b?'
Honestly, I'm still not even finished trying to make the damn thing work, I just know the approach WILL work, once I've debugged everything.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lucky Numbers
You are viewing a single comment's thread. Return to all comments →
This problem is obscenely difficult, and I spent days researching just to get fairly close to the correct solution, then I spent days more tweaking my approach to conform to the extra constraints created by the problem itself. In order to complete this in a reasonable time, you have to dig into number theory by realizing that, at least for a=1 to b=(some number of consecutive 9's), the problem resembles a permutation problem (since we take the sums/squares of these numbers, the question becomes 'how many combinations of k digits result in a prime number between 1 and 999999999999999999 when (summed) or (squared)?' and 'how can you exclude permutations that are less than a, and greater than b?'
Honestly, I'm still not even finished trying to make the damn thing work, I just know the approach WILL work, once I've debugged everything.