Sieve of Eratosthenes is an ancient algorithm of finding prime numbers for any given range. It\'s actually about maintaining a Boolean table to check for corresponding prime no
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
So now for any given number with in the N
We can tell whether the number is prime or not in O(1) time (based on corresponding TRUE/FALSE value).
When to use this algorithm in programming?
Sieve of Eratosthenes can be very efficient for any program we require to check prime numbers for multiple times (Multiple test cases too).
In such cases, we construct the Sieve of Eratosthenes only single time and for all query each only takes O(1) time reducing the time complexity overall.
C++ implementation:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer