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 was a bit of a rabbit hole, definitely not an "easy" task. Here's the code. The idea is for each base to iterate through its powers e.g. for 2 iterate through 4, 8, 16, ... . Create a set of exponents for each power e.g. for 8 we have 8^2=2^6, 8^3=2^9, ... and therefore exponents will be 6, 9, .. . Then merge all sets. Don't do sets for the bases though to avoid timeout.
Project Euler #29: Distinct powers
You are viewing a single comment's thread. Return to all comments →
This was a bit of a rabbit hole, definitely not an "easy" task. Here's the code. The idea is for each base to iterate through its powers e.g. for 2 iterate through 4, 8, 16, ... . Create a set of exponents for each power e.g. for 8 we have 8^2=2^6, 8^3=2^9, ... and therefore exponents will be 6, 9, .. . Then merge all sets. Don't do sets for the bases though to avoid timeout.