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.
I had the same experience with sieve and BitArray in C#.
Making the sieve in the first place is just too expensive for this input. If we had many more primes to check, then pre-calculating the sieve and then just quickly referencing it when checking for primality would have been much faster than brute-checking each number individually. But in this case, there are simply too few numbers to check to justify the price of the sieve construction.
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 →
I had the same experience with sieve and BitArray in C#.
Making the sieve in the first place is just too expensive for this input. If we had many more primes to check, then pre-calculating the sieve and then just quickly referencing it when checking for primality would have been much faster than brute-checking each number individually. But in this case, there are simply too few numbers to check to justify the price of the sieve construction.