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.
Find the largest int in a0, make a sieve up to the square root of that once. Then instead of testing every number less than the square root of each a0, you only are testing the primes less than the squareroot of a0 using the seive you just built. It would cut down on the the number of loops especially for larger numbers.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Complexity: Primality
You are viewing a single comment's thread. Return to all comments →
Find the largest int in a0, make a sieve up to the square root of that once. Then instead of testing every number less than the square root of each a0, you only are testing the primes less than the squareroot of a0 using the seive you just built. It would cut down on the the number of loops especially for larger numbers.