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.
But you can pre-calculate prime numbers up to sqrt(n) using seive. Then you can test each number by using just primes, but not all numbers up to sqrt(n), resulting in O(sqrt(n)/log(n)) complexity.
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 →
But you can pre-calculate prime numbers up to sqrt(n) using seive. Then you can test each number by using just primes, but not all numbers up to sqrt(n), resulting in O(sqrt(n)/log(n)) complexity.