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 takes one operation out of the loop, saving a lot of CPU cycles when dealing with bigger numbers. This approach reduces the final test case by several seconds on my machine, and those numbers are only around 10^9.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
A better solution is to store the number's square root in a variable before testing. Here is a C++ example:
This takes one operation out of the loop, saving a lot of CPU cycles when dealing with bigger numbers. This approach reduces the final test case by several seconds on my machine, and those numbers are only around 10^9.